grep --files-with-matches '>' .
Search for >
in the current directory (.
) and print only the filenames of matching files (--files-with-matches
).
Note that grep
will not return anything if you give it a directory (.
) but forget to enable "recursive" mode. The correct command would be
grep --files-with-matches --recursive '>' .
or simply
grep -Rl '>' .
| sort
| uniq
Sort results, and remove duplicates.
| xargs perl -pi~ -e 's/9Kp/9K /' /home/user/DATAFILE.DAT
Run the given command (perl ...
) with every word1 from stdin passed as additional arguments.
Every file from the grep
results, and also the /home/user/DATAFILE.DAT
file, are updated by replacing the text "9Kp
" with "9K
". The old files are backed up with a trailing tilde.
1 Note: word, not line. This means that a filename with spaces will be treated as several names. xargs -d'\n'
would be better, although not perfect.
That is a little strange... well the --files-with-matches simply lists names instead of the matching lines, and obviously the search string is '>'. But the fact that the file being searched is simply the current directory '.' is weird. Not quite sure how that is supposed to work, never ouputs anything here. Is this just plain ole GNU grep? – Nicholi – 2011-07-29T18:32:15.923
There are a number of things wrong with that script. Are you sure you copied it correctly? For example, the . is telling grep to search the current directory, not the files in the current directory but the directory itself. That won't do anything. – garyjohn – 2011-07-29T18:41:02.997
| sort | uniq
can be replaced by| sort -u
– mouviciel – 2011-07-29T18:45:12.447Yep, I copied it exactly - the only thing changed is the path and .DAT filename. Thanks, I suspected it was broken but wasn't sure if I was reading it wrong. It was probably meant to be
grep --files-with-matches '>' *
. – JJ01 – 2011-07-29T19:06:47.793