#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
search and replace across multiple files with Perl
Category: Uncategorized |
Tags: Bash, batch, code, commandline, diamond, edit, editing, files, FileSystem, hacking, one-liners, perl, productivity, regex, replace, search, text, tips, tricks, wrapper
Leave a Reply
You must be logged in to post a comment.