将文件夹名称附加到unix文件的第1行

时间:2017-09-07 11:10:48

标签: shell unix command

考虑我在Unix下有一个UNIX文件夹我有一个XYZ.csv

"id","name","salary"--- Header
"1","Jon","1000"---line

输出应该是

"UNIX1","Jon","1000"

1 个答案:

答案 0 :(得分:0)

见下面的例子:

kent$  pwd
/tmp/test/UNIX

kent$  head f
"id","name","salary"--- Header
"1","Jon","1000"---line

kent$  awk -v p="$(basename $PWD)" 'NR==2{sub(/"/,"&"p)}1' f
"id","name","salary"--- Header
"UNIX1","Jon","1000"---line

如果它不是您想要的,请在您的问题中添加要求,而不是将其放在评论中。