Perl Search and Replace in files
July 6th, 2014Replace all occurrences of “oldstring” with “newstring” in all files (no recursion):
perl -pi -e 's/oldstring/newstring/g' *
Replace all occurrences of “oldstring” with “newstring” in all HTML files recursively:
perl -pi -e 's/oldstring/newstring/g' `find ./ -name *.html`
Replace all occurrences of “oldstring” with “newstring” in all files recursively:
perl -pi -e 's/oldstring/newstring/g' `grep -irl oldstring *`
Replace all occurrences of “oldstring” with “newstring” in all files recursively, excluding .svn directories:
perl -pi -e 's/oldstring/newstring/g' `grep -irl oldstring * | grep -v .svn'
Taken from this blog which seems to no longer be active.
CRLF to LF
July 6th, 2014Windows uses two bytes for end-of-line markers, namely CR and LF, while Linux and Unix only use one: LF
dos2unix filename
sed -i 's/\r$//' file
perl -pi 's/\r$//' file
Source: Shell trick: CRLF to LF
