本文介绍了如何使用特定值"XYX"替换csv文件的第二列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要将csv文件的最后一个字段替换为xyz
,请使用以下命令:
To replace last field of csv file with xyz
I use following command:
awk -F, '{$NF="xyz";}1' OFS=, file
如何用值xyz
覆盖文件的第二列?
How can I overwrite the second column of file with value xyz
?
推荐答案
在awk
中,变量NF
是当前行上的字段数.您可以引用每个字段,例如$1
,$2
... $NF
,其中$1
是第一个字段,$2
是第二个字段,直到$NF
是当前行的最后一个字段(即,如果NF
为5,则$NF
为$5
).
In awk
the variable NF
is the number of fields on the current line. You can refer to each field like $1
,$2
...$NF
where $1
is the first field and $2
is the second field, upto $NF
which is the last field on the current line (i.e. if NF
is 5 then $NF
is $5
).
$ cat file
1,2,3,4,5
$ awk '$2="XYX"' FS=, OFS=, file
1,XYX,3,4,5
这篇关于如何使用特定值"XYX"替换csv文件的第二列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!