Skip to main content
updated solution
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

GNU awk solution:

awk -F'/' '{ d=$3$1$2 }
           NR==FNR{ t=d; nextfile }
           d > t't{ 
               print "file2 has date(s) greater than in file1";
               exit 
           }' file1 file2

The output:

12/23/2017file2 has date(s) greater than in file1

GNU awk solution:

awk -F'/' '{ d=$3$1$2 }NR==FNR{ t=d; nextfile }d > t' file1 file2

The output:

12/23/2017

GNU awk solution:

awk -F'/' '{ d=$3$1$2 }
           NR==FNR{ t=d; nextfile }
           d > t{ 
               print "file2 has date(s) greater than in file1";
               exit 
           }' file1 file2

The output:

file2 has date(s) greater than in file1
updated solution
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

GNU awk solution:

awk -F'/' 'function get_time()'{ 
               return mktime(sprintf("%d %d %d 0 0 0", $3, $1, $2)) 
          d=$3$1$2 }
           NR==FNR{ t=get_time();t=d; nextfile }
           get_time()d > t' file1 file2

The output:

12/23/2017

GNU awk solution:

awk -F'/' 'function get_time(){ 
               return mktime(sprintf("%d %d %d 0 0 0", $3, $1, $2)) 
           }
           NR==FNR{ t=get_time(); nextfile }
           get_time() > t' file1 file2

The output:

12/23/2017

GNU awk solution:

awk -F'/' '{ d=$3$1$2 }NR==FNR{ t=d; nextfile }d > t' file1 file2

The output:

12/23/2017
updated solution
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68

GNU awk solution:

awk -F'/' 'function get_time(s){ 
         split(s, a, "/"); 
         return mktime(sprintf("%d %d %d 0 0 0", a[3]$3, a[1]$1, a[2]$2)) 
           }
           NR==FNR{ t=get_time($1); nextfile }
           get_time($1) > t' file1 file2

The output:

12/23/2017

GNU awk solution:

awk 'function get_time(s){ 
         split(s, a, "/"); 
         return mktime(sprintf("%d %d %d 0 0 0", a[3], a[1], a[2])) 
     }
     NR==FNR{ t=get_time($1); nextfile }
     get_time($1) > t' file1 file2

The output:

12/23/2017

GNU awk solution:

awk -F'/' 'function get_time(){ 
               return mktime(sprintf("%d %d %d 0 0 0", $3, $1, $2)) 
           }
           NR==FNR{ t=get_time(); nextfile }
           get_time() > t' file1 file2

The output:

12/23/2017
Source Link
RomanPerekhrest
  • 30.9k
  • 5
  • 47
  • 68
Loading