I am new to Linux and I have two CSV files which are sorted and having the same number of rows. I wanted to join these two CSV files.1.csv1,2,34,5,67,8,92.csv10,11,1213,14,1516,17,18result.csv1,2,3,10,11,124,5,6,13,14,157,8,9,16,17,18I tried with cat 1.csv 2.csv >result.csv but it appends instead of joining.
How to join two csv with same number of rows
linux;awk;sed;csv
Job for paste:paste -d, {1,2}.txt-d, sets the delimiter as ,. {1,2}.txt is brace expansion, done by shell, would be expanded to 1.txt 2.txt.If you fancy a bit of awk:awk 'NR==FNR {a[FNR]=$0; next} {print a[FNR], $0}' OFS=, {1,2}.txtNR==FNR will be true only for the first file; {a[FNR]=$0; next} creates an array a with record numbers as keys, and records as the valuesFor the second file, {print a[FNR], $0} prints the array element at the corresponding line number followed by current record; OFS=, sets the output field separator as ,Example:$ cat 1.txt 1,2,34,5,67,8,9$ cat 2.txt 10,11,1213,14,1516,17,18$ paste -d, {1,2}.txt1,2,3,10,11,124,5,6,13,14,157,8,9,16,17,18$ awk 'NR==FNR {a[FNR]=$0; next} {print a[FNR], $0}' OFS=, {1,2}.txt1,2,3,10,11,124,5,6,13,14,157,8,9,16,17,18