Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge two csv files in bash

Tags:

bash

I have two csv files.

Columns of the first file

col1, col2, col3,......col4095, col4096, col4097

Columns of the second file

col1, col2, col3,......,col4095, col4096, col4097

Expected output - the last column of the first file is discarded

col1, col2, col3.......,col4095. col4096, col1, col2, col3....col4095, col4096, col4097

Both files have the same number of rows, I want to merge the two files into one file.

like image 443
cpwah Avatar asked Jan 30 '26 02:01

cpwah


1 Answers

Use paste :

paste -d, f1.csv f2.csv > out.csv

To ignore last column of first file:

awk -F, 'NF-=1' OFS=, f1.csv | paste -d, - f2.csv > out.csv
like image 136
sat Avatar answered Jan 31 '26 15:01

sat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!