in reply to what regular expression do I need?
A simple regex works fine, but transliteration is often more efficient. Here's an approach with tr///. This snippet iterates over each line of each file supplied at the command prompt, and prints the filename and line number, along with a highlighted version of the line's data showing where the problems are:
while( <> ) { chomp; if( tr/IMO//c ) { s/([^IMO]+)/[-->$1<--]/g; print "File: $ARGV, Line $.: $_\n"; } }
This would be invoked as:
$ ./nonimo.pl filename1.txt filename2.txtIt could be expressed as a one-liner, in fact, like this:
perl -lnE 'if(tr/IMO//c){s/([^IMO]+)/[-->$1<--]/g; say "$ARGV-$.: $_"} +' file1.txt file2.txt fileXX.txt
The output is a little more terse, but it does the same thing. In either case, if your objective is just to print the bad lines, you can easily simplify the print statement.
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: what regular expression do I need?
by tbone654 (Beadle) on Apr 19, 2013 at 04:33 UTC |
In Section
Seekers of Perl Wisdom