Operating System - HP-UX
1821584 Members
3414 Online
109633 Solutions
New Discussion юеВ

grep for date forward in a syslog

 
SOLVED
Go to solution
KPS
Super Advisor

grep for date forward in a syslog

Hi,

This is a grep question. I'm trying to grep for a starting point in a syslog by a specific date and then capture everything else beyond that poing going forward to be able to more it in an active shell and display it. What would the syntax be to do this? I'm doing the following and don't seem to be having any luck with this:

grep "Jul 3" syslog.log | more

Thanks,
KPS
4 REPLIES 4
Ermin Borovac
Honored Contributor
Solution

Re: grep for date forward in a syslog

Don't know about grep but you can do it with sed.

$ sed -n '/Jul 3/,$p' syslog.log

This should print everything from the line matching "Jul 3" to the last line ($).
Vibhor Kumar Agarwal
Esteemed Contributor

Re: grep for date forward in a syslog

If you need you can also pass the search pattern as a variable


sed -n "/$Search_Pattern/,$p" syslog.log

Just remember to use double quotes (") instead of single one (')
Vibhor Kumar Agarwal
Muthukumar_5
Honored Contributor

Re: grep for date forward in a syslog

#!/usr/bin/ksh
LINE=$(awk '/Jul 30/{ print NR;exit; }' syslog.log)
tail -n +${LINE} syslog.log

hth
Easy to suggest when don't know about the problem!
john korterman
Honored Contributor

Re: grep for date forward in a syslog

Hi,
perhaps you can use the awk funtionality for printing everything between a starting and an end point, e.g.:

# awk '/Jul 6/,/\$/' /var/adm/syslog.log|more

(there are two spaces beteen "Jul" and "6" in the above example).

regards,
John K.
it would be nice if you always got a second chance