Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

print varaible length fields
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

Report this thread to moderator Post Follow-up to this message
Old Post
dragrid
11-26-04 08:55 PM


Re: print varaible length fields

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
11-26-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.