in reply to How to read lines between specific character
As for why your script only printed the number of ENERGY lines, you read the entire content of the file into the "@raw_data" array, and used that array to count those lines (in a rather strange, non-optimal way), but you didn't use the same array to count the other lines.perl -lne '$k=(/ENERGY/)?"e":"o";$c{$k}++;END{print "$c{e} $c{o}"}' da +ta.file
Instead, you went into a strange loop that tries to continue reading from the file (even though the entire file has already been read, so no more input is available). But you really don't need two passes over the data in any case; in a single pass, you can count the lines that contain ENERGY and the ones that don't.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to read lines between specific character
by AG87 (Acolyte) on Nov 13, 2010 at 18:55 UTC |