[英]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.