n00b0101
asked on
unix find and replace recursively
Hopefully, this will be a quick one for someone here... I need to find and replace a string recursively in unix.
Normally, I use:
But, the string I need to replace contains slashes, and I'm not sure how to escape them?
So, I need to do:
and REPLACE = '/string/path/newterm'
Normally, I use:
perl -e "s/term/differenterm/g;" -pi $(find path/to/DIRECTORY -type f)
But, the string I need to replace contains slashes, and I'm not sure how to escape them?
So, I need to do:
perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)
where FIND = '/string/path/term'and REPLACE = '/string/path/newterm'
ASKER
I tried both of those, but it returns "Illegal variable name".
perl -e "s#/string/path/term/#/string/path/newterm/#" -pi $(find ./* -type f )
Illegal variable name.
What exactly are you trying to do?
ASKER
"
So, I need to do:
where FIND = /string/path/term
and REPLACE = /string/path/newterm
"
So, I need to do:
perl -e "s/FIND/REPLACE/g;" -pi $(find path/to/DIRECTORY -type f)
where FIND = /string/path/term
and REPLACE = /string/path/newterm
"
perl -pi.bak -e 's/(\/string\/path\/)term/ $1newterm/ g;' $( find /path/to/directory -type f)
The -i option requires a suffix to a maintain a backup.
The -i option requires a suffix to a maintain a backup.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
s###;
s#/string/path/term#/strin
OR
s{/string/path/term}{/stri