Forums.ATC.no
Teknisk => Generelt teknisk => Emne startet av: ATC på 22. Oktober 2009, 14:03 pm
-
How to search and replace a string in multiple files?
-
"perl -pi -w -e 's/search/replace/g;' *.txt"
'search' is a regular expression. This means you have to escape most special characters with a backslash (\) and you can add lots of advanced stuff like pattern matching, look-ahead, look-behind etc.
-p loop through parameters (in this case, all files matching*.txt)
-i edit in-place
-w enable warnings
-e execute the quoted script
Google 'regular expressions' or 'perlretut' to learn more about how to do really cool stuff with regular expressions.