![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need help in Parsing a CSV file and generate a new output file | vkr | Shell Programming and Scripting | 15 | 08-01-2008 08:33 AM |
| Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names | nikosey | Shell Programming and Scripting | 6 | 07-30-2008 10:46 PM |
| Parsing a file | aol12123 | Shell Programming and Scripting | 11 | 03-25-2008 02:06 AM |
| Parsing a csv file | chiru_h | Shell Programming and Scripting | 6 | 02-12-2008 09:33 AM |
| Parsing a Log file | tbirenzweig | Shell Programming and Scripting | 4 | 06-20-2006 08:02 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
File Parsing Help
Hello,
I have a file which contains groups of fields. These groups are separated by a blank line, to form a logical record. Each line consists of a field-value pair. If want to find all records where field 'd' has a value of '4' and if it does, I want the value of field 'a' (from the same record). Here's an example input file: I want to end up with a file containing: Import things to nore about the input file are a) the number of records varies, b) not all records contain a 'd' field, c) not all records contain a 'a' field, e) fields can be in any order within a record. I think the answer will be to use AWK but I have very little knowledge of AWK and have only used it for very basic things. The OS is Sun 5.8 by the way. Help would be greatly appreciated. Thanks. |
|
||||
|
Unclear
Seems to be a big gap between your requirements and the output you expect. Based on what you have stated the output should look like cfajohnson's awk script...correct???
|
|
|||||
|
With Perl: Code:
perl -00 -ne'print $1,"\n"if/d 4/&&/a (.)/' filename And another AWK approach: Code:
awk '/d 4/ && /a / {
for (i=1; i<=NF; i++)
if ($i == "a") print $(i+1)
}' RS= filename
Last edited by radoulov; 10-13-2008 at 04:03 PM.. Reason: refactored |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|