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) ;
}


In reply to A new question from the front line by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.