Hi; Thanks for those who replied. This is what I find out to be the most flexible and easy to use (with inspiration from Ragnar Moller's suggestion): $ sort -k 3b,3b messages|grep -n "MAY 30"|sed -n '/11:00:00/,/12:00:00/ p' john.benjamins@sympatico.ca suggestion: To get all the messages from 00:00:00 up to 11:59:59 (but not 12:00:00 exactly) use: $ egrep 'May 30 (0[0-9]|1[01]):[0-5][0-9]:[0-5][0-9] ' messages daniel.denes@bankgesellschaft.de suggestion: add this to your grep: | nawk '{daysec = 60*60*substr($3, 0, 2)+60*substr($3, 4, 2)+substr($3, 7); if (daysec <=43200) print $0;}' Regards, TEH Hi; Following this summary from Ragnar Moller, may experts out there advise how do I grep syslog messages with format of: MAY 30 01:12:16 ... for messages with timestamp between 00:00:00 to 12:00:00? What I am looking for is something like: $ grep "MAY 30" messages| Thank you for any insight and advice. I will summarize. Regards, TEH "Ragnar Moller (MA/EAF)" wrote: > I got a lot of answers. I had a job to do so I triggered on and tried > the first one which almost evolved the "unproved" by Stephen.Grund > (but step by step). > I think they're really worth sharing for those of us who aren't yet > "fluent" in Unix. > Like I said I only tried sed, but I certainly will take the time to > try out the other ones because I'll be needing a higher performing and > table solution next round. > > Here are the answers: > Use sed by majority > Cat file | -n '/cecilia/,/frederic/ p' > Use Awk 25% > awk '/from/,/to/' filename > awk '/cecilia/,/frederic/ { print }' > Unproved by Stephen Grund > set from=`grep -n fromfirst filename | head -1 | awk -F: '{print $1}'` > set last=`grep -n tolast filename | tail -1 | awk -F: '{print $1}'` > awk '(NR>=from)&&(NR<=last)' filename > This is exactly what perl was developed for. Pretty simple to do. > Kristopher Briscoe > http://freshmeat.net/projects/cgrep James Noyes > cgrep provides many of the features of grep, egrep, and fgrep with > enhanced performance along with many additional features. One of the > most important features is the ability to output the context > (surrounding lines) of the matching lines. The context window may be > specified as a constant number of lines before and after the matching > lines, by specifying beginning and ending delimiters, or various > combinations thereof. > > Use a shell script Dwight Brewer > > #!/usr/bin/sh > > inbetween=false > echo "" > newfile > > cat data |while read line > do > start_check=`echo $line | grep cecilia` > if [ "$start_check" ] > then > ## we found start line containing cecilia > inbetween=true > fi > > if [ "$inbetween" = "true" ] > then > echo $line >> newfile > end_check=`echo $line | grep frederic` > if [ "$end_check" ] > then > ## we found end line containing frederic > inbetween=false > fi > fi > done > > > Use Perl by Ric Anderson > > Depending on how much you need to do, awk or perl will handle this > task. Something like > awk -f awkscript < your_file > where awkscript contains > { if($0 ~ /cecilia/) { > print $0;flag=1; > } > else { > if(flag == 1) { > print $0; > if($0 ~ /frederic/) { > exit(0); > } > } > } > } > will print all the information beginning with a line containing > cecilia and ending with a line containing frederic. Note the match is > case sensitive. > Minor edits to the logic here would allow suppressing the cecilia and > frederick lines and only displaying the information between those > points. > > Perl provides more powerful pattern matching, and a lot of other > useful features that make it a better choice than awk for more complex > tasks. _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagers --------------------------------- Sneak preview the all-new Yahoo.com. It's not radically different. Just radically better. _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagers Get on board. You're invited to try the new Yahoo! Mail Beta. _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagersReceived on Wed May 31 02:56:16 2006
This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:58 EST