Parsing a timestamp until EOF


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing a timestamp until EOF
# 1  
Old 09-21-2010
Parsing a timestamp until EOF

hey guys, i'm having a bit of trouble with my script. based on the time you started a shift for work, it's supposed to read the input, and then parse a log file of alerts accordingly. my issue is parsing out from the time entered as your start time until the end of the file. the format looks like this

Code:
09-21-2010 05:14:23
09-21-2010 06:25:23
09-21-2010 07:47:23
09-21-2010 08:45:23
09-21-2010 09:34:23
09-21-2010 10:10:23

so if my time started is at 7am. i'd want it to parse the file for 7am all the way down until the EOF. any help on this would be appreciated, thanks!
# 2  
Old 09-21-2010
You could do something like this:
Code:
$ sed '/^09-21-2010 07/,$!d' infile
09-21-2010 07:47:23
09-21-2010 08:45:23
09-21-2010 09:34:23
09-21-2010 10:10:23

or
Code:
sed -n '/^09-21-2010 07/,$p' infile

which is equivalent..
# 3  
Old 09-21-2010
two things, one I would be running this on different days, and months, and two im going to have the time started as a variable that is taken from user input. so it will initially prompt me what time i started, then read the input and create a variable. so essentially my variable for $SHIFT would be 7 for this example. so something like this maybe..?


Code:
sed -n '/^$SHIFT/,$p'

# 4  
Old 09-21-2010
You would need to use double quotes to let the shell expand $SHIFT
Code:
sed -n "/^$SHIFT/,$p"

# 5  
Old 09-21-2010
okay, thanks. i'll tinker with that and try to get it working.^_^
# 6  
Old 09-21-2010
Code:
D="09-21-2010"
T="07"

Or 

D=$(date +%m-%d-%Y)
T=$(date +%H)

awk -v date=$D -v time=$T '{split($2,a,":")} $1==date&&a[1]>=time' infile

This User Gave Thanks to rdcwayx For This Post:
# 7  
Old 09-22-2010
Quote:
Originally Posted by rdcwayx
Code:
D="09-21-2010"
T="07"

Or 

D=$(date +%m-%d-%Y)
T=$(date +%H)

awk -v date=$D -v time=$T '{split($2,a,":")} $1==date&&a[1]>=time' infile

awesome, thanks alot. this works perfect!^_^ i just changed the variable $T to my variable $SHIFT for hour started and it works. lol
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

4. Shell Programming and Scripting

Parsing and timestamp a pattern in log

Hello Thanks to Chubler_XL and MadeInGermany for their help few weeks ago. Now, i would like modifying the script, see the next POST. The old script works like that : I picked any random hours In the logs there is the stamp time of webservices, i can see the behavior or errors of... (3 Replies)
Discussion started by: amazigh42
3 Replies

5. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

6. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

7. Shell Programming and Scripting

Adding timestamp after cat <<EOF >

Hi Team, I am trying to add timestamp to SQLs by taking the timestamp in variable through shell script.I started like this. cat << EOF > $MYDIR CONNECT TO $MYDB USER $MYUSR USING $MYPWD; T=`db2 -x "select CURRENT_TIMESTAMP from sysibm.sysdummy1 "`; DECLARE RECCUR CURSOR FOR... (3 Replies)
Discussion started by: rocking77
3 Replies

8. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

9. Shell Programming and Scripting

confused with << EOF EOF

Hi friends , I am confused with << EOF EOF Most of the cases I found sqlplus $db_conn_str << EOF some sql staments EOF another exapmle is #!/bin/sh echo -n 'what is the value? ' read value sed 's/XXX/'$value'/' <<EOF The value is XXX EOF (1 Reply)
Discussion started by: imipsita.rath
1 Replies

10. Shell Programming and Scripting

conversion of different timestamp to standard timestamp

hi i need a scrit to convert one date format to another. for example i have three columns in a file which gets a different format, but lastly i want output with stadard timestamp as "yyyy-mm-dd hh:mm:ss" column1 column2 ... (2 Replies)
Discussion started by: dprakash
2 Replies
Login or Register to Ask a Question