in reply to A new question from the front line


Here's another way:
perl -ne 'print if $prev; $prev = /energy/' file # Or with a counter perl -ne 'print ++$i, $_ if $prev; $prev = /energy/' file
Your second solution could have been written as follows:     perl -ne 'print ++$i . <> if /energy/' filename

--
John.