I'm about half-way through this command. I'm eventually going to implement it in a PHP site so if I could keep it down to one line, that would rock!
Here's what I'm trying to do: find compressed files in a specific date, and then grep for the phone number 1234567890. The command I have so far is:
find . -newermt '2014-04-30 08:00:00' -not -newermt '2014-04-30 09:00:00'
The results are
./1006AC1.ACT.gz
./1006AC3.ACT.gz
./1006AC4.ACT.gz
./1006AC0.ACT.gz
./1006ABF.ACT.gz
./1006AC5.ACT.gz
./1006AC2.ACT.gz
This is good! But, this is also where I'm stuck. Each one of these files contains tons of records and to search the 7 compressed files I usually just:
gunzip -c 1006A* |grep 1234567890
But I'm trying to roll those two commands into one. Here's the direction I've been heading:
find . -newermt '2014-04-30 08:00:00' -not -newermt '2014-04-30 09:00:00' |xargs gunzip -c * | grep 1234567890
Unfortunately, this and the other variants I've tried either such nothing, or everything. I cannot get it to search only in the 7 files that were output.
Optionally, my other thought (because the goal is to implement it to a PHP site) would be to run my first command, and then try to find the files that match using a regex. In this case: 1006A
Then, I'd encapsulate that in a variable and send the second command similar to:
gunzip -c $compressed |grep 1234567890
My difficulty here is taking all 7 files, and outputing only the letters/numbers that are similar in all 7.
Thanks for any help! Jared
Use zgrep
:
find . -newermt '2014-04-30 08:00:00' -not -newermt '2014-04-30 09:00:00' | xargs zgrep 1234567890
zgrep
is like grep
but understands compressed files.
In your trial command, note the star after xargs gunzip -c
:
find . -newermt '2014-04-30 08:00:00' -not -newermt '2014-04-30 09:00:00' |xargs gunzip -c * | grep 1234567890
The shell will expand that star, *
, to be all the filenames in the current directory. That is not what you want and is likely why you got unexpected results from the command.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments