Operating System - HP-UX
1820676 Members
2313 Online
109626 Solutions
New Discussion юеВ

Re: grep dates on snmp collected data

 
Seun Ewulomi_1
Honored Contributor

grep dates on snmp collected data

Hi people,

I use egrep to grep on data of the format below

10/11/2003 00:00 299 0.43 0.45 140.54 68.34 72.2 32
11/11/2003 00:05 301 0.25 0.34 93.56 39.77 53.78 28
12/11/2003 00:10 300 0.34 0.37 113.91 54.08 59.83 32

1) To see all data for just a certain day I usually do
grep '^10/.*/2003'

2)to see all data for some days I usually do
egrep -e '11/.*/2003' -e '12/.*/2003' snmp.log

Now if I want to see the all data for example from 10/11/2003 - 15/11/2003 how would this be done with awk, egrep or sed.

My main aim is to see/filter all data in a snmp log file just for mondays-fridays and omitting all the weekend dates.

Any help or advice will be grately appreciated.

regards,
seun
Jesus Christ is LORD
6 REPLIES 6
RAC_1
Honored Contributor

Re: grep dates on snmp collected data

may be this will help

sed -n '/10\/11\/2002\/15\/11\/2003\/p' < input_file
There is no substitute to HARDWORK
Todd McDaniel_1
Honored Contributor

Re: grep dates on snmp collected data

If the DAY is always the first column then you can simply do.

grep '^1[1-5]/.*/2003'


Or you can script it with a read statement and input the days you want to grep for... based upon your entry, assigned to a variable.

if i have time i can post a solution like that later.
Unix, the other white meat.
Seun Ewulomi_1
Honored Contributor

Re: grep dates on snmp collected data

Hi Guys,

Thanks alo for your replies.

Todd - I would really appreciate it if you post a solution of the script that would do this(do it only if you have time). Thanks

Rac - Thanks I will be trying yours and Todds solution in a momment and il reply back.

Thanks guys

regards,
gab
Jesus Christ is LORD
Rodney Hills
Honored Contributor

Re: grep dates on snmp collected data

Have you considered using perl? It has date modules available where you could get the day of the week.

use Date::Calc;
$lower = Date_to_Days(2003,11,10);
$upper = Date_to_Days(2003,11,15);
open(INP,"while() {
chomp;
($mydate)=split(" ",$_);
($day,$mth,$yr)=Decode_Date_EU($mydate);
$date = Date_to_Days($year,$month,$day);
$dow=day_of_week($yr,$mth,$day)
next if $dow >= 6; # skip SAT,SUN
next if $date < $lower || $date > $upper;
print $_,"\n";
}

HTH

-- Rod Hills
There be dragons...
Michael Schulte zur Sur
Honored Contributor

Re: grep dates on snmp collected data

Hi,

her is my solution.

greetings,

Michael

#!/bin/ksh
while read LINE
do
DATE=`echo ${LINE} | cut -c 1-10`
DOW=`./timeconv "${LINE}" "%d/%m/%Y"|awk '{printf("%s"),$7}'`
if ([[ ${DOW} -gt 0 && ${DOW} -lt 6 ]])
then
echo ${LINE}
fi
done < logfile

timeconv.c
#include
#include
main(argc,arg)
int argc;
char **arg;
{
struct tm t;
if (argc!=3)
{
printf("Usage: arg[0] date datefmt(see man strptime)\n");
return(2);
};
strptime(arg[1],arg[2], &t);
printf("%2d %2d %2d %2d %2d %1d %3d %1d",t.tm_sec,t.tm_min,t.tm_hour,t.tm_mday
,t.tm_mon,t.tm_year,t.tm_wday,t.tm_yday,t.tm_isdst);
}

NocGuy
Occasional Contributor

Re: grep dates on snmp collected data

Just trying to touch base with ya.
i am a new HPOV admin. and just saw some answers to some questions i had which you had replied to and ws beneficial.

thinking i might be able to have a mentor in you. touch base with me, geniusaceb_j@msn.com

i am based here in texas USA.

BAYO