bronto has asked for the wisdom of the Perl Monks concerning the following question:
Hello fellow monks
Do you remember the question Save all but line 32!? Yesterday I had another question to which I gave a reply but I am interested again in how you had resolved the same issue. Here we go:
A colleague of mine asked me: "I have a text file that contains data record as lines; here and there between the data you have rows that tell you the names of the columns. If I find a line that contains, say, the word energy I want to print the line that follows it. In similar cases I resolved with awk, but I can't get a solution for this one and I don't want to code it in FORTRAN".
My solution was:
perl -ne 'print scalar <> if /energy/' filename
He then asked me if I could add a counter, and I slightly modified the previous in:
perl -ne 'print ++$i,scalar <> if /energy/' filename
What's your solution for this?
Ciao!
--bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->make($love) ;
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A new question from the front line
by jmcnamara (Monsignor) on Oct 18, 2002 at 08:31 UTC | |
|
Re: A new question from the front line
by blakem (Monsignor) on Oct 18, 2002 at 08:15 UTC | |
by Aristotle (Chancellor) on Oct 18, 2002 at 13:57 UTC | |
|
Re: A new question from the front line
by Chmrr (Vicar) on Oct 18, 2002 at 11:44 UTC |