HowTo: reg expr doing grep "timestamp>$DesiredTime" logfile ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HowTo: reg expr doing grep "timestamp>$DesiredTime" logfile ?
# 1  
Old 06-25-2009
Question HowTo: reg expr doing grep "timestamp>$DesiredTime" logfile ?

I know I asked a similar question but I want to know if there is a regular expression existing that with a korn shell cmd, finds any timestamp data records in a file where it is greater then a timestamp in a shell variable ?


something like :

grep all records where it has a timestamp > $DesiredTime from logfile-X

It would simplify my coding alot for what I want to do on the client's AIX 4.2
# 2  
Old 07-04-2009
Any ideas ?
# 3  
Old 07-04-2009
How does the format of the dates lookes like in your log file?
# 4  
Old 07-05-2009
Quote:
Originally Posted by Franklin52
How does the format of the dates lookes like in your log file?
like the standard `date` output:

I know I could always do a regular expression to match each date parts. But I need to know if there a special one that will allow me something like :
grep all records in file where any timestamp in it is > $a_given_timestamp
# 5  
Old 07-05-2009
Quote:
Originally Posted by Browser_ice
like the standard `date` output:

I know I could always do a regular expression to match each date parts. But I need to know if there a special one that will allow me something like :
grep all records in file where any timestamp in it is > $a_given_timestamp
For that I afraid you have to convert your timestamp to min or sec's before comapring it with the given timestamp(that should be also in min or in sec's)
# 6  
Old 07-05-2009
To match dates you can use a format like YYYYMMDDHH, an example to convert the date format Mar 17 16:44:03 2009 to 2009031716

Code:
echo "Mar 17 16:44:03 2009"|
awk -F" |:" '
BEGIN {
  a="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
  split(a,m,",")
  for(i=1;i<13;i++)
    n[m[i]]=i
}
{printf("%s%02d%02d%s\n", $6, n[$1], $2, $3)}
'

Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Howto auto boot SPARC | How to auto supply "start /SYS" and "start /SP/console" commands

When I power ON my T4-1, I got a prompt -> where I have to start /SYS and start /SP/console. How can I auto supply these two commands ? (3 Replies)
Discussion started by: z_haseeb
3 Replies

2. Shell Programming and Scripting

Commenting out "expr" creates weird behavior

This really puzzles me. The following code gives me the error 'expr: syntax error' when I try to do multi-line comment using here document <<EOF echo "Sum is: `expr $1 + $2`" EOF Even if I explicitly comment out the line containing the expr using "#", the error message would still exist... (3 Replies)
Discussion started by: royalibrahim
3 Replies

3. Homework & Coursework Questions

How to lclear "expr: syntax error" eventhough everything looks fine?

Hi All, As per my knowledge in unix, my code looks fine. But still I am getting error (expr:syntax error). Please help me to resolve this error. Script : PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 TOT_REM=0 TOTAL=1 for Record_Type in `cut -c 1 Inputt.dat` do if ; then CURR_LBNO=` cut -c... (6 Replies)
Discussion started by: lathanandhini
6 Replies

4. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

grep to find content in between curly braces, "{" and "},"

problem String ~~~~~~~~~~~~~~~~~~ icecream= { smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" } aend = {smart vc4 eatr kalu} output needed ~~~~~~~~~~~~~~~~~~ smart peopleLink "good" LC "happy" , smartpeopleLink "dull" LC "sad" smart vc4... (4 Replies)
Discussion started by: keshav_rk
4 Replies

10. Shell Programming and Scripting

why "expr "${REPLY}" : '\([1-9][[:digit:]]*\)" can figure out whether it is a digit?

I found below script to check whether the variable is a digit in ksh. ############################ #!/bin/ksh REPLY="3f" if ]*\)'` != ${REPLY} && "${REPLY}" != "0" ]] then print "is digit\n" else print "not digit\n" fi ############################ Although it works fine, but... (6 Replies)
Discussion started by: sleepy_11
6 Replies
Login or Register to Ask a Question