Here's a quick way to edit all files whose contents contain a given string:
files=""; for i in `find . -type f -print`; do files="$files `grep -l <text> $i`"; done; vi $files
For all file names in the current directory, including those in subdirectories, assign each in turn to the variable i.
for i in `find . -type f -print`;For each of the files we found, run the grep command to search the file provided by the $i variable.
do files="$files `grep -l <string> $i`";Edit the found files with the vi editor.vi $filesMove back and forth between files using:
:n -- move to the next file :rew -- move back :e #3 -- edit the third file in buffer :ar -- list files status
The escape characters make the regex hard to read/write (For me that is)
ie to add index.html at the end of each href - replace /" with /index.html"
find . -name "*.html" -print0 | xargs --null perl -pi -e 's/\/\"/\/index.html\"/'
This script contains perl - possibly the head honcho of text manipulation scripting languages - though perl could be replaced with grep, in this instance.