Like this:
try.pl:
#!/usr/bin/perl -w use strict; my $count = 0; while (<>) { $count += s/foo/bar/g; print; } print "Nothing found!\n" unless $count;
Show it in action:
H:\>cat try1.txt bla blurb foo foo foo lilalu H:\>cat try2.txt bla blurb fuu fuu fuu lilalu H:\>cat try1.txt | perl try.pl bla blurb bar bar bar lilalu H:\>cat try2.txt | perl try.pl bla blurb fuu fuu fuu lilalu Nothing found! H:\>
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
In reply to Re: Conditional replace
by clemburg
in thread Conditional replace
by October
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |