|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm just getting back into Unix after > 10 years away. I know I previously wrote a shell script that would recursively search through directories into each file for a particular string and replace it with something else. I just can't remember how to do this
I'm currently using ssh Can anyone help me? ![]() |
|
#2
|
|||
|
|||
|
Assuming you have access to PERL, no need to write a script. You could use the "'PERL's of Wisdom", find and xargs. Like the following:
Code:
find . | xargs perl -p -i.bak -e 's/oldString/newString/;' find . = will set up your recursive search. You can narrow your search to certain file by adding -name "*.ext" or limit buy using the same but add prune like -name "*.ext" -prune xargs =sets it up like a command line for each file find finds and will invoke the next command which is perl. perl = invoke perl -p sets up a while loop -i edit in place and the .bak will create a backup file like filename.ext.bak -e execute the following.... 's/ / /;' your basic substitute and replace. just a suggestion.... ![]() |
|
#3
|
|||
|
|||
|
Hi,
For recursive search u can used the following command find . -print | xargs -i -t grep <enter search criteria> {}|more for replacement purpose please use "sed" command. See Man sed Thanks deb_dutta Quote:
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > recursive search & replace string in any file? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|