LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2012, 10:57 AM   #1
cristalp
Member
 
Registered: Aug 2011
Distribution: Linux Mint
Posts: 103

Rep: Reputation: Disabled
BASH or AWK: extract columns in multiple files and combine to a single file


Dear all,

I have several files with multiple columns in each file. I want to extract the 2nd column from the first file and the 7th column from the second file and the 4th column from the third file and then put these 3 columns into a new file with format like below.

Code:
#This is to show the format of the new file with 3
#columns extracted from the 3 files
 
2nd           7th             4th
columns       columns         columns
of            of              of
the           the             the
first         second          third 
file          file            file

#END of the file
How could I do this in a simple way by bash script or awk?

Thanks for your help!
 
Old 03-15-2012, 11:17 AM   #2
thinknix
Member
 
Registered: Nov 2008
Distribution: Lots!
Posts: 178

Rep: Reputation: 58
Quote:
Originally Posted by cristalp View Post
I have several files with multiple columns in each file. I want to extract the 2nd column from the first file and the 7th column from the second file and the 4th column from the third file and then put these 3 columns into a new file with format like below.
I've answered this one before, see here: http://www.linuxquestions.org/questi...script-739991/

Basically, it sounds like you want this, assuming the columns are comma-delimited:

Code:
paste -d, <(cut -d, -f2 file1.csv) <(cut -d, -f7 file2.csv) <(cut -d, -f4 file3.csv) > output.csv
 
Old 03-15-2012, 11:55 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would probably like to see what you have tried as this is not for your first attempt and have been assisted a number of times before.
 
  


Reply



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
extracting columns from multiple files with awk orcaja Linux - Newbie 7 02-14-2012 10:24 PM
[SOLVED] AWK (or TCL/TK): Matching rows and columns between multiple files Euler2 Programming 6 05-30-2011 06:31 PM
awk command to merge columns from two separate files into single file? johnpaulodonnell Linux - Newbie 4 01-23-2007 10:10 AM
Command to combine several files as a single file, etc. satimis *BSD 3 06-10-2004 03:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 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
Open Source Consulting | Domain Registration