Find /Replace with Perl

Language butchery by Mr Rich on  2.6.10 @ 12:26

Uses a vi-like search and replace syntax:
perl -pi -e 's/find this/replace with this/g' /tmp/file.txt

When placed into a for loop, you get some pretty cool capabilities. For example, find string and replace with nothing:
ls -1 dir/*svg > svg-files
for file in `cat svg-files`; do perl -pi -e ' s/\/home\/richw\/screenshots\/784wide\/dir\///g' $file; done

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?