|
 |
Other Programming Languages If you have a coding issue to discuss about another language that really isn't provided for in any other forum here (not ASP.NET C#, C++, VB, PHP, JavaScript, Python, Java, Perl, Applescript, XML or any of the other forum topics we have), post it here. Enough discussion on a language we don't have covered could prompt a new forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Other Programming Languages section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

September 23rd, 2008, 08:33 AM
|
Authorized User
|
|
Join Date: Oct 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Filter records in a file with sed or awk (UNIX)
Hi all,
I would like to extract records of a file based on a condition. The file contains 47 columns, and I would like to extract only those records that match a certain value in one of the columns, e.g.
COL1 COL2 COL3 ............... COL47
1 XX 45 N
2 YY 34 y
3 ZZ 44 N
4 XX 89 Y
5 XX 45 N
6 YY 84 D
7 ZZ 22 S
From this file, I would like to extract all records whose COL2=XX or YY, and all other records will be excluded (as shown below).
COL1 COL2 COL3 ............... COL47
1 XX 45 N
2 YY 34 y
4 XX 89 Y
5 XX 45 N
6 YY 84 D
Does anybody know how to do this using sed or awk or any other UNIX tool? Thank you.
|

October 6th, 2008, 05:01 AM
|
Friend of Wrox
|
|
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Code:
awk '$2=="XX"||$2=="YY" {print $0}' your_filename
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
|

November 25th, 2008, 07:43 PM
|
Registered User
|
|
Join Date: Nov 2008
Location: leawood, ks, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I got same situation but i can't use awk program. I can only use SED command.
Is it possible to filter rows with sed command
temp.txt
1;a;200
2;b;300
3;a;400
4;c;800
5;b;900
Now i want to filter on second field if field is equal to "a" or "b" then display rows otherwise throw it.
is it doable?
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |