tags:

views:

474

answers:

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

I'm now using this command to list the records that contain my numeric string how can i alos get this command to print the name of the file the strings were found in?

thanks

+2  A: 

Use zgrep

BTW. what you're trying to do can be done with find

find  -newermt 'Mar 4' -and ! -newermt 'Mar 5' -exec zgrep -l '12345' {} \;
vartec
A: 

Pass the -t option to xargs, causing it to print the command it is running (the zcat command, including the filename) before running it. The command is printed to stderr, so it will not interfere with your pipe.

unwind
+1  A: 

If you use zgrep instead of zcat+grep (which does the same), you do it like this option like this:

ls -ltr | grep 'Mar 4' | awk '{print $9}' | xargs zgrep 12345
f3lix
A: 
$ find -maxdepth 1 -type f -newermt 'Mar 4' ! -newermt 'Mar 5' \
       -execdir zgrep 12345 '{}' /dev/null ';'
ashawley