Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > Other Programming Languages
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 23rd, 2008, 08:33 AM
Authorized User
 
Join Date: Oct 2006
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
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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
Reply With Quote
  #3 (permalink)  
Old November 25th, 2008, 08:43 PM
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?





Reply With Quote





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.