Published in: Perl
URL: http://perl.com/pub/a/2004/08/09/commandline.html?page=2
A couple of useful snippets from an article I found at Perl.com
Perl search-and-replace on the command line.
All of these should be usable under Cygwin as well. But remember that bash wants single-quoted strings but MS-DOS shell wants strings to be double-quoted.
Expand |
Embed | Plain Text
#print the result of search-and-replace to the terminal perl -pe 's/bart/milhouse/g' test.html #search-and-replace, with backup #leave the suffix off of -i to overwrite perl -i.bak -pe 's/bart/milhouse/g' test.html #echo the number of lines in a file perl -lne 'END { print $t } @w = /(\w+)/g; $t += @w' test.html #cat file with line numbers # -p prints $_ each iteration perl -pe '$_ = "$. = $_"' test.html # recursive search-and-replace, only on shells that support file globs perl -i.bak -pe 's{bart}{milhouse}' **/*html
You need to login to post a comment.