Link to home
Start Free TrialLog in
Avatar of Tricky
TrickyFlag for United States of America

asked on

repetative grep from user specified start file...

Hi,

Thanks for reading...

The filenames I need to grep start as zcat 20000101*, this obviously being the 1st of Jan this year, and need to grep to present day, for a user defined string, much like UKLIrad055232. This is the exact format, four letters caps, three small, six numbers.

~SUMMARY~

I need the grep to be automated, from user input of string to search for (which I assume is simply $1), from the 1st of Jan (ie zcat 20000101*) to present day (today being the 14th, would be zcat 20000114*), without entering finish date.

I'm using Sun OS 5.5.1, and use VI as my editor program, and will give 300 points for a working solution!!!

Thanks for your time...appreciate it very much...

Tricky.
Avatar of Tricky
Tricky
Flag of United States of America image

ASKER

Please mail lafarge4@hotmail.com
(other address is dead)...

Thx!

Tricky.
If u have perl:

try command
perl grep.pl UKLIrad055232

------- file grep.pl --------------
#!/usr/local/bin/perl

($sec,$min,$hour,$mday,$mon,$year) = localtime(time);

$mon ++;
$year += 1900;
$last = sprintf("$year%02d%02d", $mon, $mday);

for ($i = 20000101; $i< $last; $i++)
{
    system("zcat $i* |grep $ARGV[1]");
}
---------------------------------------
Avatar of Tricky

ASKER

Hi Maxkir :)

I need a seamless, complete, solution.

I need the grep string to be defined upon user input.

I understand unix, but am not fluent...in fact I know very little...

All I need to use is UNIX itself, nothing else...

Talk soon...THX..

Tricky
Avatar of ozo
In what way is maxkir's solution not seamless or complete enough for you?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ecw
ecw

#!/bin/sh
end=`date +%Y%m%d`
ls -1 2000[01][0-9][0-9][0-9]* | sed "/^$end/q" | xargs zcat | grep -e "$1"
Avatar of Tricky

ASKER

Thanks ozo... this is exactly what was required. A UNIX script, that did exactly what I asked...perfect.

Kind Regards,

Tricky.