4
ls -ltr|grep 'Mar  4'| awk '{print $9 }'|zcat -fq |grep  12345

I want to find all files modified on a certain date and then zcat them and search the fiels for a number string.

the above doesn't work because it searches the file name for the string not the file itself.

Any help?

M

4 Answers4

2

Use xargs to run the grep on the filenames output by awk:

ls -ltr | grep 'Mar 4' | awk '{print 9}' | xargs zcat -fq | grep 12345

Or, I guess, run the rest of the pipe from awk itself.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

Try using find instead. And/or xargs.

leppie
  • 115,091
  • 17
  • 196
  • 297
1

If I read your command line correctly, its zcat that is trying to unpack the filenames instead of their content. Use xargs to solve this:

ls -ltr|grep 'Mar  4'| awk '{print $9 }'|xargs zcat -fq |grep  12345
cg.
  • 3,648
  • 2
  • 26
  • 30
0

In addition to the fine answers about using xargs or find, you can also get rid of an extra process by eliminating zcat and piping to zgrep or grep -Z instead.

dwc
  • 24,196
  • 7
  • 44
  • 55