[英]Add trailer to csv using Linux
There are let's say 44 records in my csv file. 假设我的csv文件中有44条记录。 I want to add the word: 我想添加一个词:
TRAILER,44
In my CSV file using linux command. 在我的CSV文件中,使用linux命令。 How to do it? 怎么做?
I am using wc -l myfilename.csv | cut -d' ' -f1 >> myfilename.csv
我正在使用wc -l myfilename.csv | cut -d' ' -f1 >> myfilename.csv
wc -l myfilename.csv | cut -d' ' -f1 >> myfilename.csv
for word count. wc -l myfilename.csv | cut -d' ' -f1 >> myfilename.csv
进行字数统计。 I can add the word TRAILER
and word count on the next line, but was wondering if I could get them on the same line. 我可以在下一行添加单词TRAILER
和单词计数,但想知道是否可以将它们放在同一行。
awk
to the rescue! awk
解救!
$ awk '1; END{print "TRAILER," NR}' file
print all lines and at the end print trailer with line count. 打印所有行,最后打印带有行数的预告片。
To replace the original file: 替换原始文件:
$ awk ... file > tmp && mv tmp file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.