0

I have a file containing the following columns Operation,Name,Start_Time,End_time,Status.

The column Start_Time contains both date and time.

Here is from the table.

Upload | XYZ | 22/10/2014 22:00:00 | 22/10/2014 22:15:10 | finished

Upload | ABC | 22/10/2014 22:10:00 | 22/10/2014 22:30:00 | failed

Upload | EFG | 22/10/2014 23:00:00 | 22/10/2014 23:30:00 | failed

I need to extract the rows whose start_time lies between 22:00:00 and 23:00:00 both inclusive.

I tried using awk command. But couldn't succeed.

Please help.

Thanks in advance.

Shreyas

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
Shreyas Athreya
  • 103
  • 1
  • 13
  • 1
    an example would be better. – Avinash Raj Oct 28 '14 at 04:56
  • possible duplicate of [Find entries in log file within \[timespan\] (eg. the last hour)](http://stackoverflow.com/questions/7706095/find-entries-in-log-file-within-timespan-eg-the-last-hour) – tripleee Oct 28 '14 at 06:33

1 Answers1

0
awk -F\| '$3~/(22:..:..)|(23:00:00)/' inputFile

gives output as

Upload | XYZ | 22/10/2014 22:00:00 | 22/10/2014 22:15:10 | finished
Upload | ABC | 22/10/2014 22:10:00 | 22/10/2014 22:30:00 | failed
Upload | EFG | 22/10/2014 23:00:00 | 22/10/2014 23:30:00 | failed

EXPLANATION :

-F\| set input field seperator as |

$3~/(22:..:..)|(23:00:00)/ select lines in which column 3, $3 follows given pattern

(22:..:..) matches any time begining with 22

(23:00:00) matches 23:00:00

EDIT

When columns are delimited by space

$ awk  '$4~/(22:..:..)|(23:00:00)/' sam
Upload  XYZ  22/10/2014 22:00:00  22/10/2014 22:15:10  finished
Upload  ABC  22/10/2014 22:10:00  22/10/2014 22:30:00  failed
Upload  EFG  22/10/2014 23:00:00  22/10/2014 23:30:00  failed
nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
  • does it match for any date?? or only for the specified date ie., 22/10/2014? – Shreyas Athreya Oct 28 '14 at 06:06
  • actually there is no field separator as | in the file. There are spaces between the columns. How to sort out then? – Shreyas Athreya Oct 28 '14 at 06:16
  • I have one more question.. Can I give a filename as pattern in the script instead of the time I have specified? like.. $awk '4~/(filename)|(filename)/' sample ..the file contains the time interval – Shreyas Athreya Oct 28 '14 at 07:29
  • can this purpose be fulfilled by using sql queries? Start_time is a datetime field in the database. – Shreyas Athreya Oct 28 '14 at 10:12
  • the above columns in the file are present in a database..so i wanted to know if an sql query could be written to retrieve the values just like the above output ? That is by providing the time interval within a query.. – Shreyas Athreya Oct 28 '14 at 11:26
  • it can be done without the use of regex. like `hour(column) = '23'` – nu11p01n73R Oct 28 '14 at 11:30