简体   繁体   English

如何在制表符分隔的文本linux文件中的特定列中添加常量

[英]How to add constant to specific columns in tab delimited text linux file

I have a text file that looks like: 我有一个文本文件,看起来像:

cpDNA 1226 1559 Predicted1 cpDNA 1226 1559已预测1
cpDNA 2874 7748 Predicted2 cpDNA 2874 7748已预测2
cpDNA 8244 9594 Predicted3 cpDNA 8244 9594已预测3

And I would like to add a specific value (77244) to all of the values in columns 2 and 3. The spaces between columns are tabs. 我想在第2列和第3列的所有值中添加一个特定值(77244)。各列之间的空格是制表符。 How can I do this? 我怎样才能做到这一点?

$ awk -v OFS='\t' -v val=77244 '{$2+=val; $3+=val}1' file

This might work for you (GNU sed): 这可能对您有用(GNU sed):

sed 's/\S*/&77244/2;s//&77244/3' file

Or you may prefer: 或者您可能更喜欢:

val=77244; sed 's/\S*/&'$val'/2;s//&'$val'/3' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Linux中的文本文件中提取列(空格或制表符分隔) - Extracting columns (space or tab delimited) from text file in Linux awk linux取差异并添加制表符分隔列文件 - awk linux take difference and add tab delimited columns file 如何在Linux中的带有标题的制表符分隔文件中添加行名 - How to add row name in tab delimited file with header in Linux 如何在Linux中将特定文本添加到文本文件中的列? - How to add a specific text to columns in a text file in Linux? 将带有空列的行添加到制表符分隔的文件中 - add a row with empty columns to a tab delimited file 使用 bash (linux) 选择制表符分隔文件的特定行 - Selecting specific rows of a tab-delimited file using bash (linux) 修改文件中的文本(数百万列,制表符分隔) - 删除除第一个以外的所有选项卡,并在最后一列后面添加新列 - modify the text in file (millions of columns, tab-delimited) - delete all tabs except the first one and add new columns behind the final column 向制表符分隔的文件添加标题 - Add a header to a tab delimited file 使用从制表符分隔的文本文件(Linux)读取的参数运行的批处理脚本 - batch script that runs with parameters read from a tab delimited text file (Linux) 替换选项卡分隔文件linux中的封闭字符串中的选项卡 - replace tab in an enclosed string in a tab delimited file linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM