Add Columns to .csv from Multiple Files
try:
<file_list xargs -I % awk '
{ system("sed -i '\'' " NR "s/,\\?$/," $4 "/'\'' test.csv" ) }' %.txt
the xargs
is reading filename from file_list file and feed to awk
thought xarags's variable called %
with .txt
suffix as filename contains.
with sed '#s/$/something/' test.csv"
command that used to append something
at the end $
of a specific line number #
in a file like test.csv
; so at above, $4
is the string that need to appended to specific line number taking from NR
; ,\?$
is saying might your line ends with comma ,
which I used because you have it in your test.csv
. this sed
command is calling by awk
's system()
function.
note that sed
is writing in-place any changes, so you will not notice terminal ouput, do:
$ cat test.csv
0,8,4,12
1,10,6,3
2,5,9,10