0

I using this command for search all file contain this word . I want to remove all file contain this word in specific directory . grep command perfectly. suggest me how can I used

     rm -rf

with below command

     grep -l -r  -i  "Pending" . | grep -n  . | wc -l
  • [This](https://unix.stackexchange.com/questions/84852/delete-files-matching-pattern) Link will help you meet your requirements. – khalidmehmoodawan Dec 09 '17 at 08:05
  • `grep -n` already shows line numbers, hhere's no need to pipe that to `wc -l`. To just obtain the count, omit the `grep`, or simply pipe to `grep -c` if you genuinely need to filter out empty lines (but in this case you really don't; `grep -l` could certainly emit file names which contain two consecutive newlines, but if you have file names with newlines, the rest of the pipeline is broken anyway). – tripleee Dec 09 '17 at 11:07

1 Answers1

0

This could be done by using the l flag and piping the filenames to xargs:

-l (The letter ell.) Write only the names of files containing selected lines to standard output. Pathnames are written once per file searched. If the standard input is searched, a pathname of (standard input) will be written, in the POSIX locale. In other locales, standard input may be replaced by something more appropriate in those locales.

grep -l -r 'Pending' . | xargs rm

The above will delete all files in the current directory containing the word Pending.

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93