Compare dates using awk in bash











up vote
0
down vote

favorite












I have a file and each line has some info and a date,so what I want is to print the lines with dates after a given date. I use this awk command



sort -t$'|' -k5 $2 | awk -F '|' -v DatedAfter=$4 '!/^#/ && $5>=DatedAfter {print $0}'


Where $4 is a date in DD/MM/YYYY format given and $2 is the file I use in the format bellow.



1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


So when i execute my code i get these results.



./tool.sh --born-since 17/11/1983 -f events.dat
1099511629352|Nunez|Jorge|female|17/11/1986|2011-04-04T05:54:52.693+0000|201.221.59.59|Opera|Facebook
1099511638548|Phan|Don|female|17/5/1981|2011-04-19T00:14:15.041+0000|112.72.79.36|Opera|Flickr
1099511638387|Znaimer|Moses|male|17/8/1980|2011-05-12T01:03:01.291+0000|94.199.19.90|Internet Explorer|Youtube
6597069776449|Svensson|Ernst|male|30/11/1981|2012-04-22T05:16:03.557+0000|31.31.166.207|Opera|Youtube
2199023258994|Ngoche|Alex Obanda|female|30/9/1987|2011-07-22T16:36:27.420+0000|41.81.41.21|Opera|Google+
7696581405294|Dobrunov|Aleksandr|male|31/12/1989|2012-05-15T05:46:31.439+0000|31.25.243.122|Internet Explorer|LinkedIn
2199023266450|Charoenpura|Somchai|male|4/12/1987|2011-08-30T20:34:41.524+0000|110.76.154.132|Mozilla|Youtube
3298534890514|Chen|Hsin|male|4/4/1988|2011-11-03T16:32:44.238+0000|115.42.116.30|Safari|Google+
2199023261081|Ben Dhifallah|Karim|male|6/4/1980|2011-06-11T02:24:17.194+0000|193.95.74.75|Chrome|Twitter
8796093024550|Yang|Lei|male|7/1/1990|2012-07-15T17:14:42.186+0000|1.4.92.176|Mozilla|Facebook









share|improve this question
























  • I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
    – Jeff Schaller
    2 days ago










  • Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
    – Μάριος Τσοκανάς
    2 days ago












  • Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
    – Jeff Schaller
    2 days ago










  • May I doubt that it works with the first date format either?
    – RudiC
    2 days ago















up vote
0
down vote

favorite












I have a file and each line has some info and a date,so what I want is to print the lines with dates after a given date. I use this awk command



sort -t$'|' -k5 $2 | awk -F '|' -v DatedAfter=$4 '!/^#/ && $5>=DatedAfter {print $0}'


Where $4 is a date in DD/MM/YYYY format given and $2 is the file I use in the format bellow.



1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


So when i execute my code i get these results.



./tool.sh --born-since 17/11/1983 -f events.dat
1099511629352|Nunez|Jorge|female|17/11/1986|2011-04-04T05:54:52.693+0000|201.221.59.59|Opera|Facebook
1099511638548|Phan|Don|female|17/5/1981|2011-04-19T00:14:15.041+0000|112.72.79.36|Opera|Flickr
1099511638387|Znaimer|Moses|male|17/8/1980|2011-05-12T01:03:01.291+0000|94.199.19.90|Internet Explorer|Youtube
6597069776449|Svensson|Ernst|male|30/11/1981|2012-04-22T05:16:03.557+0000|31.31.166.207|Opera|Youtube
2199023258994|Ngoche|Alex Obanda|female|30/9/1987|2011-07-22T16:36:27.420+0000|41.81.41.21|Opera|Google+
7696581405294|Dobrunov|Aleksandr|male|31/12/1989|2012-05-15T05:46:31.439+0000|31.25.243.122|Internet Explorer|LinkedIn
2199023266450|Charoenpura|Somchai|male|4/12/1987|2011-08-30T20:34:41.524+0000|110.76.154.132|Mozilla|Youtube
3298534890514|Chen|Hsin|male|4/4/1988|2011-11-03T16:32:44.238+0000|115.42.116.30|Safari|Google+
2199023261081|Ben Dhifallah|Karim|male|6/4/1980|2011-06-11T02:24:17.194+0000|193.95.74.75|Chrome|Twitter
8796093024550|Yang|Lei|male|7/1/1990|2012-07-15T17:14:42.186+0000|1.4.92.176|Mozilla|Facebook









share|improve this question
























  • I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
    – Jeff Schaller
    2 days ago










  • Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
    – Μάριος Τσοκανάς
    2 days ago












  • Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
    – Jeff Schaller
    2 days ago










  • May I doubt that it works with the first date format either?
    – RudiC
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a file and each line has some info and a date,so what I want is to print the lines with dates after a given date. I use this awk command



sort -t$'|' -k5 $2 | awk -F '|' -v DatedAfter=$4 '!/^#/ && $5>=DatedAfter {print $0}'


Where $4 is a date in DD/MM/YYYY format given and $2 is the file I use in the format bellow.



1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


So when i execute my code i get these results.



./tool.sh --born-since 17/11/1983 -f events.dat
1099511629352|Nunez|Jorge|female|17/11/1986|2011-04-04T05:54:52.693+0000|201.221.59.59|Opera|Facebook
1099511638548|Phan|Don|female|17/5/1981|2011-04-19T00:14:15.041+0000|112.72.79.36|Opera|Flickr
1099511638387|Znaimer|Moses|male|17/8/1980|2011-05-12T01:03:01.291+0000|94.199.19.90|Internet Explorer|Youtube
6597069776449|Svensson|Ernst|male|30/11/1981|2012-04-22T05:16:03.557+0000|31.31.166.207|Opera|Youtube
2199023258994|Ngoche|Alex Obanda|female|30/9/1987|2011-07-22T16:36:27.420+0000|41.81.41.21|Opera|Google+
7696581405294|Dobrunov|Aleksandr|male|31/12/1989|2012-05-15T05:46:31.439+0000|31.25.243.122|Internet Explorer|LinkedIn
2199023266450|Charoenpura|Somchai|male|4/12/1987|2011-08-30T20:34:41.524+0000|110.76.154.132|Mozilla|Youtube
3298534890514|Chen|Hsin|male|4/4/1988|2011-11-03T16:32:44.238+0000|115.42.116.30|Safari|Google+
2199023261081|Ben Dhifallah|Karim|male|6/4/1980|2011-06-11T02:24:17.194+0000|193.95.74.75|Chrome|Twitter
8796093024550|Yang|Lei|male|7/1/1990|2012-07-15T17:14:42.186+0000|1.4.92.176|Mozilla|Facebook









share|improve this question















I have a file and each line has some info and a date,so what I want is to print the lines with dates after a given date. I use this awk command



sort -t$'|' -k5 $2 | awk -F '|' -v DatedAfter=$4 '!/^#/ && $5>=DatedAfter {print $0}'


Where $4 is a date in DD/MM/YYYY format given and $2 is the file I use in the format bellow.



1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


So when i execute my code i get these results.



./tool.sh --born-since 17/11/1983 -f events.dat
1099511629352|Nunez|Jorge|female|17/11/1986|2011-04-04T05:54:52.693+0000|201.221.59.59|Opera|Facebook
1099511638548|Phan|Don|female|17/5/1981|2011-04-19T00:14:15.041+0000|112.72.79.36|Opera|Flickr
1099511638387|Znaimer|Moses|male|17/8/1980|2011-05-12T01:03:01.291+0000|94.199.19.90|Internet Explorer|Youtube
6597069776449|Svensson|Ernst|male|30/11/1981|2012-04-22T05:16:03.557+0000|31.31.166.207|Opera|Youtube
2199023258994|Ngoche|Alex Obanda|female|30/9/1987|2011-07-22T16:36:27.420+0000|41.81.41.21|Opera|Google+
7696581405294|Dobrunov|Aleksandr|male|31/12/1989|2012-05-15T05:46:31.439+0000|31.25.243.122|Internet Explorer|LinkedIn
2199023266450|Charoenpura|Somchai|male|4/12/1987|2011-08-30T20:34:41.524+0000|110.76.154.132|Mozilla|Youtube
3298534890514|Chen|Hsin|male|4/4/1988|2011-11-03T16:32:44.238+0000|115.42.116.30|Safari|Google+
2199023261081|Ben Dhifallah|Karim|male|6/4/1980|2011-06-11T02:24:17.194+0000|193.95.74.75|Chrome|Twitter
8796093024550|Yang|Lei|male|7/1/1990|2012-07-15T17:14:42.186+0000|1.4.92.176|Mozilla|Facebook






bash shell-script awk date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Μάριος Τσοκανάς

256




256












  • I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
    – Jeff Schaller
    2 days ago










  • Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
    – Μάριος Τσοκανάς
    2 days ago












  • Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
    – Jeff Schaller
    2 days ago










  • May I doubt that it works with the first date format either?
    – RudiC
    2 days ago


















  • I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
    – Jeff Schaller
    2 days ago










  • Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
    – Μάριος Τσοκανάς
    2 days ago












  • Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
    – Jeff Schaller
    2 days ago










  • May I doubt that it works with the first date format either?
    – RudiC
    2 days ago
















I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
– Jeff Schaller
2 days ago




I assume (please confirm) that the first line of code in your question is part of a script which expects a filename as the 2nd parameter and a date (in the format of DD-MM-YYYY?) as the 4th parameter?
– Jeff Schaller
2 days ago












Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
– Μάριος Τσοκανάς
2 days ago






Not exactly, the command i use is like this ./exec.sh -f <file> --born-since <DD/MM/YYYY>.
– Μάριος Τσοκανάς
2 days ago














Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
– Jeff Schaller
2 days ago




Please edit that incoming date format into the question, so answerers knows how to compare it. Thank you!
– Jeff Schaller
2 days ago












May I doubt that it works with the first date format either?
– RudiC
2 days ago




May I doubt that it works with the first date format either?
– RudiC
2 days ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










It will be easier if the dates are in YYYYMMDD (then they will be in lexicographic and numeric order). You can use gensub for that in awk. For example:



awk -F"|" -v d="$d" -v dp='(..)/(..)/(....)' 'BEGIN {gensub(dp, "321", d)} {dt=$5; gensub(dp, "321", dt);} dt >= d' foo


The d variable holds the date for comparison, and dp holds the pattern matching a DD/MM/YYYY date. Then with gensub, we move around those (3, 2, 1 being the matched groups ((....), the second (..), the first (..), respectively). Same with the fifth field of each line, which we copy to avoid modifying the input.



I expanded your example input with some more dates:



1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/04/1977|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/03/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


And got this result using 19/04/1978 for comparison:



1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer





share|improve this answer








New contributor




Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    1
    down vote













    How about



    DT="01/08/1989"
    awk -F| -vDT=${DT:6}${DT:3:2}${DT:0:2} 'substr($5, 7) substr($5, 4, 2) substr($5, 1, 2) > DT' file
    1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox





    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482319%2fcompare-dates-using-awk-in-bash%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote



      accepted










      It will be easier if the dates are in YYYYMMDD (then they will be in lexicographic and numeric order). You can use gensub for that in awk. For example:



      awk -F"|" -v d="$d" -v dp='(..)/(..)/(....)' 'BEGIN {gensub(dp, "321", d)} {dt=$5; gensub(dp, "321", dt);} dt >= d' foo


      The d variable holds the date for comparison, and dp holds the pattern matching a DD/MM/YYYY date. Then with gensub, we move around those (3, 2, 1 being the matched groups ((....), the second (..), the first (..), respectively). Same with the fifth field of each line, which we copy to avoid modifying the input.



      I expanded your example input with some more dates:



      1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
      1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/04/1977|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/03/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


      And got this result using 19/04/1978 for comparison:



      1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
      1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer





      share|improve this answer








      New contributor




      Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        up vote
        3
        down vote



        accepted










        It will be easier if the dates are in YYYYMMDD (then they will be in lexicographic and numeric order). You can use gensub for that in awk. For example:



        awk -F"|" -v d="$d" -v dp='(..)/(..)/(....)' 'BEGIN {gensub(dp, "321", d)} {dt=$5; gensub(dp, "321", dt);} dt >= d' foo


        The d variable holds the date for comparison, and dp holds the pattern matching a DD/MM/YYYY date. Then with gensub, we move around those (3, 2, 1 being the matched groups ((....), the second (..), the first (..), respectively). Same with the fifth field of each line, which we copy to avoid modifying the input.



        I expanded your example input with some more dates:



        1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
        1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/04/1977|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/03/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


        And got this result using 19/04/1978 for comparison:



        1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
        1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer





        share|improve this answer








        New contributor




        Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          It will be easier if the dates are in YYYYMMDD (then they will be in lexicographic and numeric order). You can use gensub for that in awk. For example:



          awk -F"|" -v d="$d" -v dp='(..)/(..)/(....)' 'BEGIN {gensub(dp, "321", d)} {dt=$5; gensub(dp, "321", dt);} dt >= d' foo


          The d variable holds the date for comparison, and dp holds the pattern matching a DD/MM/YYYY date. Then with gensub, we move around those (3, 2, 1 being the matched groups ((....), the second (..), the first (..), respectively). Same with the fifth field of each line, which we copy to avoid modifying the input.



          I expanded your example input with some more dates:



          1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
          1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1977|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/03/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


          And got this result using 19/04/1978 for comparison:



          1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer





          share|improve this answer








          New contributor




          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          It will be easier if the dates are in YYYYMMDD (then they will be in lexicographic and numeric order). You can use gensub for that in awk. For example:



          awk -F"|" -v d="$d" -v dp='(..)/(..)/(....)' 'BEGIN {gensub(dp, "321", d)} {dt=$5; gensub(dp, "321", dt);} dt >= d' foo


          The d variable holds the date for comparison, and dp holds the pattern matching a DD/MM/YYYY date. Then with gensub, we move around those (3, 2, 1 being the matched groups ((....), the second (..), the first (..), respectively). Same with the fifth field of each line, which we copy to avoid modifying the input.



          I expanded your example input with some more dates:



          1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox
          1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1977|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/03/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer


          And got this result using 19/04/1978 for comparison:



          1099511633435|Smith|Jack|male|19/04/1978|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1979|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer
          1099511633435|Smith|Jack|male|19/04/1980|2010-05-26T03:45:11.772+0000|50.72.193.218|Internet Explorer






          share|improve this answer








          New contributor




          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 2 days ago









          Elayne

          732




          732




          New contributor




          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Elayne is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.
























              up vote
              1
              down vote













              How about



              DT="01/08/1989"
              awk -F| -vDT=${DT:6}${DT:3:2}${DT:0:2} 'substr($5, 7) substr($5, 4, 2) substr($5, 1, 2) > DT' file
              1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox





              share|improve this answer

























                up vote
                1
                down vote













                How about



                DT="01/08/1989"
                awk -F| -vDT=${DT:6}${DT:3:2}${DT:0:2} 'substr($5, 7) substr($5, 4, 2) substr($5, 1, 2) > DT' file
                1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  How about



                  DT="01/08/1989"
                  awk -F| -vDT=${DT:6}${DT:3:2}${DT:0:2} 'substr($5, 7) substr($5, 4, 2) substr($5, 1, 2) > DT' file
                  1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox





                  share|improve this answer












                  How about



                  DT="01/08/1989"
                  awk -F| -vDT=${DT:6}${DT:3:2}${DT:0:2} 'substr($5, 7) substr($5, 4, 2) substr($5, 1, 2) > DT' file
                  1099511628908|Chen|Wei|female|02/08/1989|2010-05-24T20:52:26.582+0000|27.98.244.108|Firefox






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  RudiC

                  3,0811211




                  3,0811211






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482319%2fcompare-dates-using-awk-in-bash%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      サソリ

                      広島県道265号伴広島線

                      Setup Asymptote in Texstudio