![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
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! |
|
||||
|
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! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|