Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sed to combine multiple csv files

Tags:

bash

csv

sed

I have 3 csv files I'd like to combine. Each file has 3 comma delimited columns.

File 1 has columns a,b,c
File 2 has columns d,e,f
File 3 has columns g,h,i

I'd like to combine the 3 files into a single file of:

a,b,c,e,f,h

Can I use sed to do that?

I could write a console app or script easily enough but I'm attempting to get some sed skills and believe this should be a suitable task?

like image 401
sipsorcery Avatar asked Dec 13 '22 19:12

sipsorcery


2 Answers

Or just cut and paste:

paste -d ',' file[123] | cut -d ',' -f 1,2,3,5,6,8
like image 123
Matt Mendell Avatar answered Dec 21 '22 23:12

Matt Mendell


You can do:

paste file[123] | sed 's/\t/,/g' | cut -d',' -f 1,2,3,5,6,8
like image 41
codaddict Avatar answered Dec 22 '22 00:12

codaddict