Code Comments
Programming Forum and web based access to our favorite programming groups.If you have a log output , how can you print a record header and subsequent fields , even if the fields that follow each record header is of variable lengths. ( i guess the hard part for me is to print a range of fields until i see the next header) eg record header name lucy (field) charless (field) ron (field) record header phone num 111-222-3333 555-111-4444 record header age 34 (field) 45 (field ) 21 (field) all these people live in acton (field) want to end up with just name and age through out the file. record header name lucy charles ron record header age 34 45 21 all these people live in acton (field) Thanks
Post Follow-up to this message
dragrid wrote:
> If you have a log output , how can you print a record header and
> subsequent fields , even if the fields that follow each record header
> is of variable lengths. ( i guess the hard part for me is to print a
> range of fields until i see the next header)
> eg
> record header name
> lucy (field)
> charless (field)
> ron (field)
> record header phone num
> 111-222-3333
> 555-111-4444
> record header age
> 34 (field)
> 45 (field )
> 21 (field)
> all these people live in acton (field)
>
> want to end up with just name and age through out the file.
> record header name
> lucy
> charles
> ron
> record header age
> 34
> 45
> 21
> all these people live in acton (field)
>
> Thanks
Assuming that there really is some pattern represented above by the text
"record header", then you can use that as the Record Separator and a
newline for the field separator, e.g. (untested):
awk -F"\n" -vRS="record header " '$1=="name"||$1=="age"{print RT $0}'
Regards,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.