Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-19-2015, 10:56 PM   #1
LQ Newbie
Registered: Mar 2015
Posts: 2

Rep: Reputation: Disabled
Thumbs up 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!!
Old 03-19-2015, 11:24 PM   #2
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 331

Rep: Reputation: 60
How about awk?
 awk -F' ' '{print $1,$3,$4,$5}' OFS="," file.csv
or cut & tr:
cat file.csv | tr ' ' ',' | cut -d',' -f1,3,4,5
1 members found this post helpful.
Old 03-22-2015, 09:30 PM   #3
LQ Newbie
Registered: Mar 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled

Thanks, that was good!
Old 03-23-2015, 12:32 AM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,623

Rep: Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942Reputation: 2942
Please mark as SOLVED once you have a solution.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] A challenging script - Replace field of CSV file based on another CSV file arbex5 Programming 11 06-12-2013 06:56 AM
concatenate multiple patches into one file bryanvick Linux - Software 1 11-07-2011 12:36 PM
Multiple grep outputs appended to single row of CSV file findme.krish Linux - Newbie 5 09-12-2010 06:56 PM
Create 1 csv file from multiple txt files richmur Programming 10 09-03-2008 01:28 PM
Combine output of multiple files in one CSV file say_hi_ravi Programming 4 07-17-2008 03:04 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration