1

I'm using grep -ril to be able to see all files that contain a certain string:

[user@machine]$ grep -ril "test string"
file1.log
file2.log
file3.log
file4.log
...

I then would like to zip all of the files that have been returned by that command. Is this possible?

I've tried things such as grep -ril myPattern | zip files.zip and grep -ril myPattern | zip > files.zip but nothing has worked so far.

Is there a workaround to this?

Thank you.

Ress
  • 57

2 Answers2

3

Use the zip command line switch -@ to have zip take the list of input files from standard input instead of from the command line. For example,

grep -ril "test string" | zip name-of-new-zip-file -@ 
Bob
  • 6,366
0

You can try the command on this way:

zip zipfile.zip `grep -ril "test string"`
Romeo Ninov
  • 6,677