I have a file with below contents. Here i need to compare the timestamp of HIW.ear in the first line with the timestamp of .jars from the second line and i am running out of ideas on how to do this. Any help on this please. The .ear timestamp should be lesser than all the other .jar timestamps.

[rba@ci01 UAT]$ cat UAT1.txt
UAT - NODE1,May18;21:00;HIW.ear
  • That isnt a typo, Pulled in that value from another variable into this file May 19, 2021 at 8:46

2 Answers 2


You could awk both timestamps to extract them, then arrange the timestamp in the yyyy-mm-dd hh:MM:ss format, convert them to epoch time with date --date='2021/05/18 21:00:22' +"%s" and then compare the epoch time to see which is greater.


You don't say what should happen if the comparison fails, but given

$ cat -n UAT1.txt
     1  UAT - NODE1,May18;21:00;HIW.ear
     2  May18;21:01;O.jar
     3  May18;21:01;Com.jar
     4  May18;20:59;D.jar
     5  May18;21:01;F.jar

then using perl, with the Time::Piece module:

$ perl -MTime::Piece -F';' -pe '
    if($. == 1) {
      ($s,$md) = split(/,/,$F[0]);
      $t0 = Time::Piece->strptime($md . $F[1], "%B%d%H:%M");
    $t = Time::Piece->strptime($F[0] . $F[1], "%B%d%H:%M");
    die "Timestamp out of order" if $t < $t0;
  ' UAT1.txt
UAT - NODE1,May18;21:00;HIW.ear
Timestamp out of order at -e line 8, <> line 4.

Note that it's not clear from your example whether the month specifier should be %B or %b since you happen to have chosen the one month whose English full name and abbreviated name are the same.

You could do something similar with GNU awk (gawk) but you'd need to roll your own strptime using string functions to wrangle the elements into a format suitable for mktime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.