Shell – Read columns from file, then column into an exsisting csv file

columnscsvlinuxshell-scripttext processing

Essentially, I have a csv file that contain multiple columns, called cols.csv

1,a,100
2,b,200
3,c,300
4,e,400

and I have a new csv file that has one column, called col.csv

f
g
h
i

I want to copy the items in col.csv and append them to the end of each line in cols.csv so that, cols.csv now contains those

1,a,100,f
2,b,200,g
3,c,300,h
4,e,400,i

is that possible at all? i tried join, paste, nothing worked

Best Answer

Contents of test1.txt

1,a,100
2,b,200
3,c,300
4,e,400

Contents of test2.txt

f
g
h
i

Sample.

$ paste -d, test1.txt test2.txt 
1,a,100,f
2,b,200,g
3,c,300,h
4,e,400,i

Explanation

We're using the -d flag to set the delimiter to a ,

Related Question