in reply to delete line from pattern matching
In an effort to minimize the changes to your existing strategy:
$cmdperl = "perl -i -nle 'print if !/abc.sql/ || $found++;' abc.cronta +b";
The first time that /abc.sql/ matches, the || logical short circuit will evaluate $found to be 'false', and thus no 'print will take place. However, because the $found++ expression was evaluated, $found will be incremented, making it "true". The next time /abc.sql/ matches, the || logical short circuit will evaluate $found as true, and will print. So the first time the "drop line" is found it gets skipped, and all other lines get printed.
There may be more elegant (a Perl-afficionado's eyes) pure-Perl solutions, but sometimes the best solution is to just fix the line that needs fixing, and move on. ;)
By the way: This is untested, so change the -i flag to -i.bak until you're sure it does what you want.
Dave
|
|---|