how to replace a string in multiple file & sub directories
Need to replace the following string :
#!../../../../TCL-Source/work/bin/expect by #!/usr/bin/expect in multiple .exp files and in sub directories. Thanks |
Hi, welcome to LQ!
Something like Code:
find . -type f -name \*exp | xargs -i sed -i.ori 's@#!../../../../TCL-Source/work/bin/expect@#!/usr/bin/expect@' {} What we do is start searching in the current directory, look for everything that's a) an ordinary file and b) ends in .exp. We send all the found files through sed and have it in-place replace the string "#!../../../../TCL-Source/work/bin/expect" with "#!/usr/bin/expect", and creating a back-up file with the extension .ori tacked on. Cheers, Tink |
Code:
find /path -type f -iname "*.exp" -exec sed -i.bak 's|#!../../../../TCL-Source/work/bin/expect|#!/usr/bin/expect|' "{}" +; |
Ghostdog, out of curiosity: what benefit do you see
in using the exec statement? In my personal experience exec adds a bit of latency to execution. Cheers, Tink |
I was thinking maybe just force the change of the first line:
Code:
find /path -type f -iname '*.exp' -exec sed -i.bak '1s@.*@#!/usr/bin/expect@' {} \; |
Quote:
|
All times are GMT -5. The time now is 12:23 PM. |