There are probably loads of ways of doing this. Here's how I'd approach it:
- BACKUP your files!
- Use find to get a list of the files in the sub-directories of /opt/ibm/websphere
- use xargs and fgrep (with -l option) on the list of files to identify which files contain the string we want to replace
- use xargs and sed to modify those files.
This can all be done in a single pipeline
Code:
find /opt/ibm/websphere -type f -print0 | \
xargs -0 fgrep -l -Z flyingsk1 | \
xargs -0 sed -i 's/flyingsk1/flyingskupdated2/g'
OK, here's how it works:
- find lists all the files we want to check. The -print0 option means to delimit the output with the NUL (\0) character. This prevents problems if some of the file names have spaces, newlines, tabs or other weird character in them.
- xargs with the -0 option read the list of \0 delimited file names and passes them as arguments to "fgrep -l -Z flyingsk1"
- "fgrep -l -Z flyingsk1" takes the files specified and checks to see if any of them contain the string "flyingsk1". If a file contains the string, the -l option tells fgrep to prints the filename. The -Z option makes the output delimited with the \0 character.
- The second xargs feeds the list of files (now just those which contain our string) to the sed command.
- The sed command edits the files in-place (that's what the -i option is for) making the substitution as required.