Junes
January 18, 2012, 5:02am
1
Scripting Guru's,
I need your help, can you tell me how i can check a file from a certain point onwards via a ksh script.
Currerntly i am checking the whole file and can't script it so it checks from 17.01.2012 20:00:00 onwards please..
Any help will be greatly appericated.
See file format below
File being checked
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA4140 -d hcart -p Scratchpool
CA4140 NEEDS LABELLING 17.01.2012 05:35:27
V10111 LABELED 17.01.2012 12:07:02
V10028 LABELED 17.01.2012 19:04:13
V10097 LABELED 17.01.2012 19:44:17
Check from this point onwards
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA5128 -d hcart -p Scratchpool
CA5128 NEEDS LABELLING 17.01.2012 20:04:09
/usr/openv/netbackup/bin/admincmd/bplabel -o -java -m CA5129 -d hcart -p Scratchpool
CA5129 NEEDS LABELLING 17.01.2012 20:04:09
awk ' BEGIN {ok=0}
$(NF-1)=="17.01.2012" && substr($(NF),1,2) == 20 {ok=1}
ok==0 {next}
{print} ' inputfile |grep 'whatever you are looking for'
Junes
January 23, 2012, 9:01am
3
Thanks Jim worked fine... But the only issue is the the string $YESTERDAY, is not being picked up properly... If i enter a data "17.01.2012" works fine...
How can i make it pick up the string, without failing please.
$\(NF-1\)=="17.01.2012" && substr\($\(NF\),1,2\) == 20 \{ok=1\}
YESTERDAY=20120122
$(NF-1)==$YESTERDAY && substr($(NF),1,2) == 20 {ok=1}
You need to pass YESTERDAY as a parameter to awk
awk '{...}' YESTERDAY="20120122" inputfile | ...
HTH
--ahamed
Junes
January 23, 2012, 9:24am
5
Still not picking up the informaiton
Script
awk ' BEGIN {ok=0}
$(NF-1)==$YESTERDAY && substr($(NF),1,2) >= 15 {ok=1}
ok==0 {next}
{print} ' DATE1=`date +%Y%m%d` YESTERDAY=`date -d "$DATE1 last day " "+%Y%m%d"` /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.$YESTERDAY | grep label | egrep -v "MEDIA_DEASSIGN_CALLED|NEEDS LABELLING|LABELED "
OUTPUT
+ egrep -v 'MEDIA_DEASSIGN_CALLED|NEEDS LABELLING|LABELED '
+ awk $' BEGIN {ok=0}\n $(NF-1)==$YESTERDAY && substr($(NF),1,2) >= 15 {ok=1}\n ok==0 {next}\n {print} ' DATE1=20120123 YESTERDAY=20120122 /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.20120122
Do not use "$" with YESTERDAY... use it like this $(NF-1)==YESTERDAY
And your file seems to have date with dotted notation and the date you are passing to awk is without dots.
--ahamed
Junes
January 23, 2012, 9:28am
7
Removed $, made no differnce....
Doesn't seem it being passed.
Did you check my second point?
--ahamed
---------- Post updated at 06:31 AM ---------- Previous update was at 06:29 AM ----------
Shouldn't date be passed like this? date +%d.%m.%Y
--ahamed
Junes
January 23, 2012, 9:31am
9
+ awk $' BEGIN {ok=0}\n $(NF-1)==YESTERDAY && substr($(NF),1,2) >= 15 {ok=1}\n ok==0 {next}\n {print} ' DATE11=20120123 YESTERDAY1=20120122 /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.20120122
Check my previous post (#8 ) for the date format!
--ahamed
Junes
January 23, 2012, 9:37am
11
Yes it is being passed like that my friend
SCRIPT
awk ' BEGIN {ok=0}
$(NF-1)==YESTERDAY1 && substr($(NF),1,2) >= 15 {ok=1}
ok==0 {next}
{print} ' DATE11=`date +%d.%m.%Y` YESTERDAY1=`date -d "$DATE11 last day " "+%d.%m.%Y"` /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.$YESTERDAY | grep label | egrep -v "MEDIA_DEASSIGN_CALLED|NEEDS LABELLING|LABELED "
OUTPUT
+ awk $' BEGIN {ok=0}\n $(NF-1)==YESTERDAY && substr($(NF),1,2) >= 15 {ok=1}\n {print} ' DATE11=23.01.2012 YESTERDAY1=22.01.2012 /usr/openv/netbackup/bin/MEDIA_DEASSIGN_CALLED.20120122
---------- Post updated at 02:37 PM ---------- Previous update was at 02:35 PM ----------
Working now... me being silly, with the string name... Many thanks.