hankknight
asked on
FreeBSD: Recursively find and replace text
Using a command line in FreeBSD, how can I replace the word "foobar" with the word "zooph" in all files that are found in a directory and all its subdirectories?
ASKER
Would that rename the files? I want the file names to remain the same. The text content should be changed.
aah.. I misunderstood, yes the above would rename the files..
grep -rl 'foobar' ./ | xargs sed -i 's/foobar/zooph/g'
This will search for the string 'foobar' in all files relative to the current directory and replace 'foobar' with 'zooph' for each occurrence of the string in each file.
sorry for the earlier confusion
/r
Richard
This will search for the string 'foobar' in all files relative to the current directory and replace 'foobar' with 'zooph' for each occurrence of the string in each file.
sorry for the earlier confusion
/r
Richard
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$ shopt -s globstar
$ rename -n 's/foobar/zooph/' **
remove the -n after you test and confirm.
the shopt -s globstar is to enable the bash ** feature, (stands for recursive) however it might be enabled already.
/r
Richard