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

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!

You could do something like this:

$ 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

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

which is equivalent..

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..?

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

You would need to use double quotes to let the shell expand $SHIFT

sed -n "/^$SHIFT/,$p"

okay, thanks. i'll tinker with that and try to get it working.:slight_smile:

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
1 Like

awesome, thanks alot. this works perfect!:slight_smile: i just changed the variable $T to my variable $SHIFT for hour started and it works. lol