joeymac has asked for the wisdom of the Perl Monks concerning the following question:
Hello Magnanimous Monks,
I am attempting to rewrite some Bash scripts that use a lot of awk pipes into Perl. I am looking for the best way to read in information from a repetitive text file. The text file looks something like this:
Some Field : some value Another Field: 1234 Different One: 5678 Yet Another : foo . . .
etc...
And then the "pattern" repeats (many times) in the text file. The end result is to print it all out in neat columns with headers at the top, something like:
something number1 number2 word some value 1234 5678 foo some else 4321 8765 bar
I started out putting the whole text into an array and grepping out what I want, put that was quickly becoming very messy. My second attempt is trying to extract multiple lines using the method:
while(<>){ if ( /Some Field/ ... /Yet Another/ ) { push (@array, $_); #do something with the info... } }
I found my self wanting to then put it into an array as above but that will most likely end up being the same messy situation.
I would greatly appreciate any ideas or suggestions about an easy way to extract the bits of info that I want and print them out into the desire column format (using sprintf I reckon). Also as a side note, the Perl will need to be somewhat portable (i.e. it'll run under Windows, Linux, and OSX OS's).
Thanks in advance!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Extracting and manipulating a range of lines
by GrandFather (Saint) on Oct 18, 2013 at 22:49 UTC | |
by marinersk (Priest) on Oct 19, 2013 at 07:50 UTC | |
Re: Extracting and manipulating a range of lines
by LanX (Saint) on Oct 18, 2013 at 19:11 UTC | |
Re: Extracting and manipulating a range of lines
by marinersk (Priest) on Oct 18, 2013 at 21:11 UTC | |
Re: Extracting and manipulating a range of lines
by Lennotoecom (Pilgrim) on Oct 20, 2013 at 21:17 UTC |