The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
repeated column data filter and make as a row vasanth_vadalur Shell Programming and Scripting 2 06-16-2009 08:01 AM
extract data from a data matrix with filter criteria ssshen Shell Programming and Scripting 7 04-16-2009 11:38 AM
Filter data from text file b_sri Windows & DOS: Issues & Discussions 18 04-16-2008 11:41 AM
validation of data using filter (awk or other that works...) in csv files Rafael.Buria Shell Programming and Scripting 1 03-05-2008 02:36 PM
filter data deep.singh UNIX for Dummies Questions & Answers 3 08-15-2005 12:24 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2009
Muhammad Rahiz Muhammad Rahiz is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 12
How to filter data

Hi all,

I require assistance in this.

I'd like to filter the following data to extract WADRAIN.

RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24109, 1011, 1.6, 0, 6,
RAIN, 2003-01-01 00:00, 1, DLY3208, 900, 1, 30747, 1011, 1.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24775, 1011, 2.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1622, 1011, 2.7, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1624, 1011, 1.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WAMRAIN, 900, 31, 24953, 1011, 84.5, 0, 6,
RAIN, 2003-01-01 00:00, 0, DLY3208, 900, 1, 24953, 1012, 1, 0, 1,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 31, 24953, 1022, 84, 0, 22576,

The eventual output I want is;

RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24109, 1011, 1.6, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24775, 1011, 2.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1622, 1011, 2.7, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1624, 1011, 1.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WAMRAIN, 900, 31, 24953, 1011, 84.5, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 31, 24953, 1022, 84, 0, 22576,

Thanks!
  #2 (permalink)  
Old 10-23-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,134
Hi.


Code:
man grep

  #3 (permalink)  
Old 10-24-2009
Muhammad Rahiz Muhammad Rahiz is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 12
Thanks scottn,

I did

> grep -H "WADRAIN" infile.txt > outfile.txt

and got what I wanted.

This is relatively straightforward but I also want to filter data from other columns (containing 1s and 0s) after extracting "WADRAIN". For example, how do I filter the rows containing 1s from, say, column 4?

Example:

RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24109, 1011, 1.6, 0, 6,
RAIN, 2003-01-01 00:00, 0, WADRAIN, 900, 1, 24775, 1011, 2.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1622, 1011, 2.7, 0, 6,
RAIN, 2003-01-01 00:00, 0, WADRAIN, 900, 1, 1624, 1011, 1.8, 0, 6,
RAIN, 2003-01-01 00:00, 1, WAMRAIN, 900, 31, 24953, 1011, 84.5, 0, 6,
RAIN, 2003-01-01 00:00, 0, WADRAIN, 900, 31, 24953, 1022, 84, 0, 22576,

Desired result:
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 24109, 1011, 1.6, 0, 6,
RAIN, 2003-01-01 00:00, 1, WADRAIN, 900, 1, 1622, 1011, 2.7, 0, 6,
RAIN, 2003-01-01 00:00, 1, WAMRAIN, 900, 31, 24953, 1011, 84.5, 0, 6,

Thanks!
  #4 (permalink)  
Old 10-24-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,423
then use awk...

Code:
awk -F"," '/WADRAIN/&&$3==1{print}' filename

  #5 (permalink)  
Old 10-24-2009
Muhammad Rahiz Muhammad Rahiz is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 12
Thanks vidyadhar85,

Could you tell me what the syntax means?
  #6 (permalink)  
Old 10-24-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,134
Hi.

It means if the line contains the string WADRAIN and field three contains the number 1, then print the line

Fields are separated by a comma (-F",")

If you want WAMRAIN too, then:


Code:
awk -F, '/WA[DM]RAIN/ && $3' filename


Last edited by scottn; 10-24-2009 at 02:38 PM.. Reason: added WAMRAIN!
  #7 (permalink)  
Old 10-24-2009
Muhammad Rahiz Muhammad Rahiz is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 12
Thanks scottn!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 06:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0