Matthew L. Abrasax Matthew L. Abrasax - 1 year ago 77
Perl Question

perl: print remaining string only if there is no character before the matched value.

The following prints the entire content of the line after "B. "

perl -ne'print if /B[.] (.*)/s' $string > file

How can I match/print the line only if there is no other character before the "B. "? In other words, if there is a character before the
"B. "
skip the line / do not print.

The correct "B." is always on a new line, the only correct line to match appears as follows:

B. some text here

Answer Source

A regex with a leading carat indicates that the expression should match only if it is the first item on the line. The pattern /^B[.] (.*)/s should get you the result you're looking for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download