[英]Add number of line with awk
i would to know how can i edit my csv file to add first column with name 'linenumber' and iterate through each line and insert the number of the line in this column ? 我想知道如何编辑我的csv文件以添加名称为'linenumber'的第一列并遍历每行并将行号插入此列中?
Something like that 像这样
TEST TEST2 TEST3
valu value value
To that 为了那个
linenumber TEST TEST2 TEST3
1 valu value value
Thanks in advance 提前致谢
Stoufiler Stoufiler
Following awk should help you on same. 跟随awk应该可以帮助您。
awk 'FNR==1{print "linenumber",$0;next} {print FNR-1,$0}' Input_file
In case you need to edit the Input_file itself then following may help you. 如果您需要编辑Input_file本身,那么以下内容可能会对您有所帮助。
awk 'FNR==1{print "linenumber",$0;next} {print FNR-1,$0}' OFS="," Input_file > temp_file && mv temp_file Input_file
i found the answer, it's that 我找到了答案,就是这样
awk 'FNR==1{print "linenumber,"$0;next} {print FNR-1,$0}' OFS="," input.csv > output.csv
thanks for all 谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.