Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > Other Programming Languages
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old September 23rd, 2008, 08:33 AM
Authorized User
Join Date: Oct 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Reply With Quote
  #2 (permalink)  
Old October 6th, 2008, 05:01 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts

awk '$2=="XX"||$2=="YY" {print $0}' your_filename
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote
  #3 (permalink)  
Old 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

  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


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?

Reply With Quote

Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to apply filter to shrink combo box records beetle_jaipur Access 3 July 28th, 2007 01:58 AM
Filter Records in a continuous form darrenb Access 2 June 1st, 2007 06:50 AM
Filter records using a combo box tixe83 Access 2 August 3rd, 2006 12:43 PM
How to filter records based on selection of combox method Access 1 June 30th, 2005 03:34 AM

All times are GMT -4. The time now is 08:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.