如何使用unix命令在csv文件中编辑特定列? [英] How to edit a particular column in csv file with unix command?
本文介绍了如何使用unix命令在csv文件中编辑特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个脚本,每天将新列添加到csv表中.
I want to write a script that will add new columns daily to a csv sheet.
该脚本每天运行一次,并将追加到csv文件中.现在如何编辑csv文件?编辑将通过awk或sed命令进行.我将使用此csv文件向用户发送邮件,并将其用于excelsheets中.
The script will run daily and will append to csv file. Now how to edit csv file ? Edit will be via awk or sed commands. I will use this csv file to send mail to users and it will be used in excelsheets.
我在经历的所有问题中都没有找到任何相关的答案,因此请尝试回答.
I have not found any relavent answers from all questions i have been through so please try to answer it .
推荐答案
您可以尝试使用awk
进行一些操作:
You can try something with awk
:
awk 'BEGIN{FS=OFS=","}{$NF=$NF",new_stuff"}1' csv
$ cat csv
1,shoes,red
2,apple,black
3,fog,blue
4,elephant,gray
5,monkey,green
$ awk 'BEGIN{FS=OFS=","}{$NF=$NF",new_stuff"}1' csv
1,shoes,red,new_stuff
2,apple,black,new_stuff
3,fog,blue,new_stuff
4,elephant,gray,new_stuff
5,monkey,green,new_stuff
这篇关于如何使用unix命令在csv文件中编辑特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文