Advanced string search + selection

Hi All,

I want to run a script that will search backwards through a text file until it finds a certain string, something like "Date/Time/Eng" and select a string which happens to be a date and save that as a variable.

The line will always be in the following exact format:

Date/Time/Eng. : YYYY-MM-DD / HH:MM / XXXX ZZ

where I want to save the bold date and time as a variable (START).
(I will later use this variable as a start value to calculate time elapsed between START and END)

Also I am assuming that the string will be recognized as a date + time by UNIX.

I have a script that can select all text between two strings and output it to a text file but I'm too inexperienced to adapt that.

Could someone provide some help please?

Thanks in advance

M

Like this?

START=$(awk '/Date\/Time\/Eng/{s=$3 " " $5}END{print s}' file)

Hey,

do I replace "file" with the filepath/filename?

Thanks for the reply btw

Yes.

Thank you

---------- Post updated at 01:03 PM ---------- Previous update was at 07:14 AM ----------

Hi,

I have been trying to get this to work without any joy,

The following is the code I am using (please excuse any fundamental mistakes) EDIT: By excuse I meant be patient with me, please do, of course point out the mistakes

#/usr/xpg4/bin/awk

START=$(awk '/Date\/Time\/Eng/{s=$3 " " $5}END{print s}' /usr/asm/atl.0000/user_data/error_logs/ASML_LOGBOOK.TXT) 

END=$(date +%Y-%m-%d, date +%H:%M, "")
DIFF=$(( $END - $START ))
echo "Total downtime = $DIFF"

When I run this on my UNIX machine (running SunOS 5.10) the following is displayed:

I have a feeling I am doing something wrong either with the first line or the awk command.