How can I print a message for each substitution in my Perl one-liner?
I use the following Perl syntax in my bash script:
perl -i –pe 'next if /^ *#/; s/(\b|\D)$ENV{OLD }(\b|\D)/$1$ENV{NEW }$2/' file
I want to find the OLD word without first "#" character in the file , then replaces the OLD word with NEW word
My question: I want to print "replace $OLD with $NEW" 开发者_JAVA技巧each time perl replace the $OLD with $NEW
In which way? we can insert the command: print "replaced $OLD with $NEW "; in the Perl syntax?
Please notice that perl one-liner syntax is part of my bash script
perl -i –pe 'next if /^ *#/; s/(\b|\D)$ENV{OLD }(\b|\D)/$1$ENV{NEW }$2/ && warn "replaced $OLD with $NEW\n"' file
perl -i –pe 'next if /^ *#/; s/(\b|\D)$ENV{OLD }(\b|\D)/$1$ENV{NEW }$2/ && print STDERR "replaced $OLD with $NEW\n"' file
精彩评论