LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to concatenate strings under multiple headings in .csv file into a new file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-concatenate-strings-under-multiple-headings-in-csv-file-into-a-new-file-4175537300/)

Boxcroft 03-19-2015 10:56 PM

How to concatenate strings under multiple headings in .csv file into a new file?
 
Hi guys,

I have multiple .csv files with multiple columns/headings, set up essentially like this (obviously more info in the real thing)


Gene Location Ref Var Coverage Function
DMD chrX.... A G 198 exonic
SCN4A chr17.... T C 111 splicing

and so on...

How could I concatenate selected columns into an output file with strings seperated with a comma? eg DMD,A,G,exonic (similar to what you can do in excel). I would like to be able to do this for multiple files in a directory. It would be preferable if all the outputs could be compiled into one file as I'll use this for something else later.
The current protocol in our team is to concatenate each file individually with an excel macro and copy into a file, and it takes a very long time.

Thanks very much!!

propofol 03-19-2015 11:24 PM

How about awk?
Code:

awk -F' ' '{print $1,$3,$4,$5}' OFS="," file.csv
or cut & tr:
Code:

cat file.csv | tr ' ' ',' | cut -d',' -f1,3,4,5

Boxcroft 03-22-2015 09:30 PM

thanks
 
Thanks, that was good!

grail 03-23-2015 12:32 AM

Please mark as SOLVED once you have a solution.


All times are GMT -5. The time now is 08:56 AM.