LinuxQuestions.org
Register a domain and help support LQ
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 08-18-2010, 11:14 AM   #1
secondchanti
LQ Newbie
 
Registered: Jul 2010
Posts: 23

Rep: Reputation: 15
How to cut multiple columns at a time.


Friends,

I am having a souce file (say SOURCEFILE) as below with 5 columns and many rows.

pol name status loan address
123 aaa 21 100 RJY
234 bbb 31 200 RMY
345 ccc 21 300 SJY
456 ddd 41 400 pqr

i want to compare the file (say COMPAREFILE ) which is below :

123
345

I need the following output file (sayOUTPUTFILE) as below :
( ie for file COMPAREFILE i need column 2, column 4 ie name and loan from source file )

ie output file required is to be like below :
123 aaa 100
345 ccc 400

Till now iam using the following method.
1. cutting column 2nd column
2. again cutting 4th column
3. in third, step merging the 2nd and 4 th column.

Friends, pl tell me method of writting single line command or any awk programme to do this in one step.

Thanks

Rao



I need output file (say OUTPUTFILE) as below
 
Old 08-18-2010, 11:30 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
If its delimetered nicely then awk is your friend
Something like:
Code:
awk '{if(FNR == NR)a[$0]++;else if($1 in a)print $1,$2,$4}' COMPAREFILE SOURCEFILE > OUTPUTFILE
 
  


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
how to cut two columns in data file and print file secondchanti Linux - Newbie 6 07-16-2010 07:01 AM
AWK - combining multiple columns AlexYZ Programming 5 02-24-2010 08:09 AM
printing multiple columns with awk kdelover Programming 16 12-16-2009 10:10 AM
sort by multiple columns wakatana Linux - Newbie 5 10-18-2009 04:35 PM


All times are GMT -5. The time now is 12:48 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