Add minutes to date time column

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
2
down vote

favorite












Thanks to various contributors resolving my previous request.



I need to add minutes to the date column to get new datetime stamp value. I have a file : afile.txt



1,2012-02-16,abc,aa,455,340
3,2015-02-16,dsa,dl,350,200
2,2015-02-16,aws,sw,555,180
4,2015-02-16,yyz,aa,1220,210


I have used awk (as provided to me by contributors earlier) --



awk -F, '/,/ 
printf "%s, %s, %s, %s, %s %02d:%02d, %sn",
$1, $2, $3, $4,
$2, int($5 / 100), $5 % 100,
$6
' afile.txt > bfile.txt

bfile.txt
1, 2012-02-16, abc, aa, 2012-02-16 04:55, 340
3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 200
2, 2015-02-16, aws, sw, 2015-02-16 05:55, 180
4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 210


I want to add column 5 and 6 and get the new timestamp.



Your help is much appreciated.







share|improve this question


























    up vote
    2
    down vote

    favorite












    Thanks to various contributors resolving my previous request.



    I need to add minutes to the date column to get new datetime stamp value. I have a file : afile.txt



    1,2012-02-16,abc,aa,455,340
    3,2015-02-16,dsa,dl,350,200
    2,2015-02-16,aws,sw,555,180
    4,2015-02-16,yyz,aa,1220,210


    I have used awk (as provided to me by contributors earlier) --



    awk -F, '/,/ 
    printf "%s, %s, %s, %s, %s %02d:%02d, %sn",
    $1, $2, $3, $4,
    $2, int($5 / 100), $5 % 100,
    $6
    ' afile.txt > bfile.txt

    bfile.txt
    1, 2012-02-16, abc, aa, 2012-02-16 04:55, 340
    3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 200
    2, 2015-02-16, aws, sw, 2015-02-16 05:55, 180
    4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 210


    I want to add column 5 and 6 and get the new timestamp.



    Your help is much appreciated.







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Thanks to various contributors resolving my previous request.



      I need to add minutes to the date column to get new datetime stamp value. I have a file : afile.txt



      1,2012-02-16,abc,aa,455,340
      3,2015-02-16,dsa,dl,350,200
      2,2015-02-16,aws,sw,555,180
      4,2015-02-16,yyz,aa,1220,210


      I have used awk (as provided to me by contributors earlier) --



      awk -F, '/,/ 
      printf "%s, %s, %s, %s, %s %02d:%02d, %sn",
      $1, $2, $3, $4,
      $2, int($5 / 100), $5 % 100,
      $6
      ' afile.txt > bfile.txt

      bfile.txt
      1, 2012-02-16, abc, aa, 2012-02-16 04:55, 340
      3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 200
      2, 2015-02-16, aws, sw, 2015-02-16 05:55, 180
      4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 210


      I want to add column 5 and 6 and get the new timestamp.



      Your help is much appreciated.







      share|improve this question














      Thanks to various contributors resolving my previous request.



      I need to add minutes to the date column to get new datetime stamp value. I have a file : afile.txt



      1,2012-02-16,abc,aa,455,340
      3,2015-02-16,dsa,dl,350,200
      2,2015-02-16,aws,sw,555,180
      4,2015-02-16,yyz,aa,1220,210


      I have used awk (as provided to me by contributors earlier) --



      awk -F, '/,/ 
      printf "%s, %s, %s, %s, %s %02d:%02d, %sn",
      $1, $2, $3, $4,
      $2, int($5 / 100), $5 % 100,
      $6
      ' afile.txt > bfile.txt

      bfile.txt
      1, 2012-02-16, abc, aa, 2012-02-16 04:55, 340
      3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 200
      2, 2015-02-16, aws, sw, 2015-02-16 05:55, 180
      4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 210


      I want to add column 5 and 6 and get the new timestamp.



      Your help is much appreciated.









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 27 at 0:01









      steeldriver

      62.1k1196163




      62.1k1196163










      asked May 26 at 23:52









      I Singh

      442




      442




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote













          I'm assuming that the last field should be interpreted in the same fashion as the penultimate one i.e. 340 means an offset of 3 hours and 40 minutes.



          If that is correct, then using GNU awk's Time Functions you could do



          awk '
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(d[1]" "d[2]" "d[3]" "int($5 / 100)" "$5 % 100" 0");
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 3600 * int($6 / 100) + 60 * ($6 % 100))
          1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 08:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 05:50
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:15
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 14:30


          If the last field is simply minutes, then the math for $6 is easier:



          awk ' 
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(sprintf("%d %d %d %d %d 0", d[1], d[2], d[3], int($5 / 100), $5 % 100));
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 60 * $6) 1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 10:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 07:10
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:55
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 15:50





          share|improve this answer






















          • My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
            – I Singh
            May 27 at 2:28










          • @ISingh please see updated answer
            – steeldriver
            May 27 at 2:34










          • You are an angel. Thank you so much for helping me so quickly.
            – I Singh
            May 27 at 2:36










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1040725%2fadd-minutes-to-date-time-column%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote













          I'm assuming that the last field should be interpreted in the same fashion as the penultimate one i.e. 340 means an offset of 3 hours and 40 minutes.



          If that is correct, then using GNU awk's Time Functions you could do



          awk '
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(d[1]" "d[2]" "d[3]" "int($5 / 100)" "$5 % 100" 0");
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 3600 * int($6 / 100) + 60 * ($6 % 100))
          1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 08:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 05:50
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:15
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 14:30


          If the last field is simply minutes, then the math for $6 is easier:



          awk ' 
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(sprintf("%d %d %d %d %d 0", d[1], d[2], d[3], int($5 / 100), $5 % 100));
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 60 * $6) 1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 10:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 07:10
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:55
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 15:50





          share|improve this answer






















          • My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
            – I Singh
            May 27 at 2:28










          • @ISingh please see updated answer
            – steeldriver
            May 27 at 2:34










          • You are an angel. Thank you so much for helping me so quickly.
            – I Singh
            May 27 at 2:36














          up vote
          5
          down vote













          I'm assuming that the last field should be interpreted in the same fashion as the penultimate one i.e. 340 means an offset of 3 hours and 40 minutes.



          If that is correct, then using GNU awk's Time Functions you could do



          awk '
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(d[1]" "d[2]" "d[3]" "int($5 / 100)" "$5 % 100" 0");
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 3600 * int($6 / 100) + 60 * ($6 % 100))
          1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 08:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 05:50
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:15
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 14:30


          If the last field is simply minutes, then the math for $6 is easier:



          awk ' 
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(sprintf("%d %d %d %d %d 0", d[1], d[2], d[3], int($5 / 100), $5 % 100));
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 60 * $6) 1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 10:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 07:10
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:55
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 15:50





          share|improve this answer






















          • My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
            – I Singh
            May 27 at 2:28










          • @ISingh please see updated answer
            – steeldriver
            May 27 at 2:34










          • You are an angel. Thank you so much for helping me so quickly.
            – I Singh
            May 27 at 2:36












          up vote
          5
          down vote










          up vote
          5
          down vote









          I'm assuming that the last field should be interpreted in the same fashion as the penultimate one i.e. 340 means an offset of 3 hours and 40 minutes.



          If that is correct, then using GNU awk's Time Functions you could do



          awk '
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(d[1]" "d[2]" "d[3]" "int($5 / 100)" "$5 % 100" 0");
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 3600 * int($6 / 100) + 60 * ($6 % 100))
          1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 08:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 05:50
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:15
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 14:30


          If the last field is simply minutes, then the math for $6 is easier:



          awk ' 
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(sprintf("%d %d %d %d %d 0", d[1], d[2], d[3], int($5 / 100), $5 % 100));
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 60 * $6) 1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 10:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 07:10
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:55
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 15:50





          share|improve this answer














          I'm assuming that the last field should be interpreted in the same fashion as the penultimate one i.e. 340 means an offset of 3 hours and 40 minutes.



          If that is correct, then using GNU awk's Time Functions you could do



          awk '
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(d[1]" "d[2]" "d[3]" "int($5 / 100)" "$5 % 100" 0");
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 3600 * int($6 / 100) + 60 * ($6 % 100))
          1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 08:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 05:50
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:15
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 14:30


          If the last field is simply minutes, then the math for $6 is easier:



          awk ' 
          BEGINFS=","; OFS=", "

          split($2,d,"-");
          t0 = mktime(sprintf("%d %d %d %d %d 0", d[1], d[2], d[3], int($5 / 100), $5 % 100));
          $5 = strftime("%Y-%m-%d %H:%M", t0);
          $6 = strftime("%Y-%m-%d %H:%M", t0 + 60 * $6) 1' afile.txt
          1, 2012-02-16, abc, aa, 2012-02-16 04:55, 2012-02-16 10:35
          3, 2015-02-16, dsa, dl, 2015-02-16 03:50, 2015-02-16 07:10
          2, 2015-02-16, aws, sw, 2015-02-16 05:55, 2015-02-16 08:55
          4, 2015-02-16, yyz, aa, 2015-02-16 12:20, 2015-02-16 15:50






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 27 at 2:33

























          answered May 27 at 1:16









          steeldriver

          62.1k1196163




          62.1k1196163











          • My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
            – I Singh
            May 27 at 2:28










          • @ISingh please see updated answer
            – steeldriver
            May 27 at 2:34










          • You are an angel. Thank you so much for helping me so quickly.
            – I Singh
            May 27 at 2:36
















          • My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
            – I Singh
            May 27 at 2:28










          • @ISingh please see updated answer
            – steeldriver
            May 27 at 2:34










          • You are an angel. Thank you so much for helping me so quickly.
            – I Singh
            May 27 at 2:36















          My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
          – I Singh
          May 27 at 2:28




          My fault. The last line is number of minutes that needs to be added to 5th column (date : yyyy-mm-dd hh:mm).
          – I Singh
          May 27 at 2:28












          @ISingh please see updated answer
          – steeldriver
          May 27 at 2:34




          @ISingh please see updated answer
          – steeldriver
          May 27 at 2:34












          You are an angel. Thank you so much for helping me so quickly.
          – I Singh
          May 27 at 2:36




          You are an angel. Thank you so much for helping me so quickly.
          – I Singh
          May 27 at 2:36












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1040725%2fadd-minutes-to-date-time-column%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Which professions warranted travel in Medieval times?

          How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

          Trouble downloading packages list due to a “Hash sum mismatch” error