On 03/26/2010 02:02 PM, Joseph L. Casale wrote:
I think there is a way to do it in sed using the holding space, but it's so much easier in perl that I never bothered to learn the hard parts. What's the problem with using perl anyway?
No problem, just thought there was a sexier way to do it then my ugly way. The Perl solution would be just as long if it were a one liner, so I'll just shove it into a shell script I guess.
i you're worried about slurping the whole file
perl -pe '/# comment/ and $c=1; $c and s/service-one/foo-bar/g' \ test_file.txt
works for me
slurping the whole files and replacing inline (with backups) you could do
perl -i.save -0777 -pe \ 's/(# comment)(.*)(service-one)/$1$2 foobar/msg' file1 file2 ...
K