LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-19-2015, 10:56 PM   #1
Boxcroft
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
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 331

Rep: Reputation: 59
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
 
1 members found this post helpful.
Old 03-22-2015, 09:30 PM   #3
Boxcroft
LQ Newbie
 
Registered: Mar 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
thanks

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

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:22 AM.

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