Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
First off, I am not very skilled in UNIX. I need to grep the contents of a sar file for entries between the hours of 8:30am and 10:30am.
a typical line in the file looks like this:
06:05:01 AM all 0.12 0.00 0.07 0.00 99.82
I've paged through some grep docs and the man pages on the net for a little advice, but I'm not havng much luck. Any ideas?Thanks in advance

You are asking for a solution that is very tedious. Unix doesn't handle date arithmetic very well - especially when the time is given in AM/PM.
Here's where I would start:
1) create your sar file - something like:
sar -o /tmp/data.file
2) use sar's -h option to provide the time in seconds from the epoch:
sar -h -f /tmp/data.file
Now, you can more easily perform arthmetic on the date. You still have the problem in getting the number of epoch seconds for 0830 on any given date, but that's easier than messing with AM/PM times. Since you are using GNU tools, start with the unix date command %s formatting option.

I hope that this script will do your job,if the script is in the exact format that you have given here.
terminal=`tty`
exec < prob1
while read line
do
line1=`echo $line|grep AM|cut -d" " -f1`
if [ ! -z $line1 ]
then
hr=`echo $line1|cut -d":" -f1`
min=`echo $line1|cut -d":" -f2`
if [ \( $hr -eq 08 -a $min -ge 30 \) -o \( $hr -eq 10 -a $min -le 30 \) -o \
( $hr -gt 8 -a $hr -lt 10 \) ]
then
echo $line
fi
fi
done
exec < $terminalif you don't understand anything anywhere,just ask.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |