简体   繁体   中英

In Perl, how do I output (print) all lines that follow a string?

I need to process a log file. I send it to Perl via <STDIN> . I need to output only the summary, which follows a line that contains several equal signs.

The summary is the last bit in the daily log. So, I need everything starting after the line with the = s through EOF.

I tried using a while loop with a " next unless " but I could not get that to work.

You need a flag or two loops.


Includes the trigger line in the output:

perl -e'
   while (<>) {
      last if /===/;
   }

   if (defined($_)) {
      print;
      while (<>) {
         print;
      }
   }
' log

perl -ne'print if $print ||= /===/' log

Doesn't include the trigger line in the output:

perl -e'
   while (<>) {
      last if /===/;
   }

   if (defined($_)) {
      while (<>) {
         print;
      }
   }
' log

perl -ne'last if /===/; END { print while <> }' log

perl -ne'print if $print; $print ||= /===/' log

perl -ne'print unless 1 .. /===/' log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM