How to sum time with part of milliseconds using bash?Leap seconds and dateHow to sum time using bash?bash +...

Interaction between Ethereal Absolution versus Edgar Markov with Captivating Vampire

Nuclear decay triggers

Why the color Red in Us, what is the significance?

Are required indicators necessary for radio buttons?

Unbiased estimator of exponential of measure of a set?

Why does my air conditioner still run, even when it is cooler outside than in?

Don't teach Dhamma to those who can't appreciate it or aren't interested

Can a Beast Master ranger choose a swarm as an animal companion?

How to decide whether an eshop is safe or compromised

Changing a TGV booking

How do you call it when two celestial bodies come as close to each other as they will in their current orbits?

How to think about joining a company whose business I do not understand?

How to translate 脑袋短路 into English?

Has there ever been a truly bilingual country prior to the contemporary period?

What animal has fat with the highest energy density?

Convert HTML color to OLE

Writing/buying Seforim rather than Sefer Torah

In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?

How do slats reduce stall speed?

What fuel is J005311 burning?

How did Apollo 15's depressurization work?

Using は before 欲しい instead が

Vacuum collapse -- why do strong metals implode but glass doesn't?

Sous vide chicken without an internal temperature of 165



How to sum time with part of milliseconds using bash?


Leap seconds and dateHow to sum time using bash?bash + how to define array variable with instance numberIssues with storing an echo of a date conversion into a string variable inunixHow to print the values of variables with incremented numbers using a loop in shell script?shell script works fine when executed in terminal, but errors out when ran as concurrent programparallel processing reading from a file in a loopbash + compare variable with spacesModifying a shell variable with regex (bash)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















How get sum, for ezample 00:03:03.333, of 00:01:01.111 and 00:02:02.222 into variable



EPOCH='jan 1 1970'
offset=$EPOCH

lsdvd -c VIDEO_TS | grep "Length:" | grep "Chapter:" | awk '{print($4)}' | while read -r len
do
len=${len:0:12}
offset="$(date -u -d "$EPOCH $len" +%T.%3N) + $(date -u -d "$offset" +%T.%3N)"
echo "need sum" $offset "then" ffmpeg -ss $offset ... -t $len ...
done









share|improve this question































    0















    How get sum, for ezample 00:03:03.333, of 00:01:01.111 and 00:02:02.222 into variable



    EPOCH='jan 1 1970'
    offset=$EPOCH

    lsdvd -c VIDEO_TS | grep "Length:" | grep "Chapter:" | awk '{print($4)}' | while read -r len
    do
    len=${len:0:12}
    offset="$(date -u -d "$EPOCH $len" +%T.%3N) + $(date -u -d "$offset" +%T.%3N)"
    echo "need sum" $offset "then" ffmpeg -ss $offset ... -t $len ...
    done









    share|improve this question



























      0












      0








      0


      0






      How get sum, for ezample 00:03:03.333, of 00:01:01.111 and 00:02:02.222 into variable



      EPOCH='jan 1 1970'
      offset=$EPOCH

      lsdvd -c VIDEO_TS | grep "Length:" | grep "Chapter:" | awk '{print($4)}' | while read -r len
      do
      len=${len:0:12}
      offset="$(date -u -d "$EPOCH $len" +%T.%3N) + $(date -u -d "$offset" +%T.%3N)"
      echo "need sum" $offset "then" ffmpeg -ss $offset ... -t $len ...
      done









      share|improve this question














      How get sum, for ezample 00:03:03.333, of 00:01:01.111 and 00:02:02.222 into variable



      EPOCH='jan 1 1970'
      offset=$EPOCH

      lsdvd -c VIDEO_TS | grep "Length:" | grep "Chapter:" | awk '{print($4)}' | while read -r len
      do
      len=${len:0:12}
      offset="$(date -u -d "$EPOCH $len" +%T.%3N) + $(date -u -d "$offset" +%T.%3N)"
      echo "need sum" $offset "then" ffmpeg -ss $offset ... -t $len ...
      done






      shell-script time






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 16 at 20:47









      user1855805user1855805

      11 bronze badge




      11 bronze badge

























          1 Answer
          1






          active

          oldest

          votes


















          2














          sh can only do integer arithmetic so you have to use something else, like bc (or a language that can do non-integer arithmetic such as awk or perl).



          To use bc, you first have to convert the %H:%M:%S.%3N format to seconds (including the decimal fraction) and then pipe that into bc.



          For example:



          #!/bin/bash

          epoch='1970-01-01'

          len1='00:01:01.111'
          len2='00:02:02.222'

          # convert to seconds
          len1_s=$(date -u -d "$epoch $len1" '+%s.%3N')
          len2_s=$(date -u -d "$epoch $len2" '+%s.%3N')

          # add the seconds
          sum_s=$( echo "$len1_s + $len2_s" | bc )

          echo $len1_s + $len2_s = $sum_s

          # convert back to H:M:S.N
          sum=$(date -u -d "@$sum_s" '+%T.%3N')

          echo $len1 + $len2 = $sum


          Output:



          $ ./sum.sh 
          61.111 + 122.222 = 183.333
          00:01:01.111 + 00:02:02.222 = 00:03:03.333


          I'll leave implementing that in your while loop to you....but I will note that lsdvd has some useful output options that will give you the chapter lengths in seconds (so you don't need to convert them). Probably the most useful is the XML output option which can then be processed with xmlstarlet or xml2 to extract the chapter lengths.



          e.g. here's lsdvd's XML output converted to a line-oriented format (suitable for processing with awk or whatever) using xml2:



          It's an approx 48 minute video with 11 chapters, most of which are roughly 5 mins (300 seconds) long.



          $ lsdvd -c -Ox '/path/to/some/dvd.iso'  | xml2
          /lsdvd/device=/path/to/some/dvd.iso
          /lsdvd/title=TITLE
          /lsdvd/vmg_id=DVDVIDEO-VMG
          /lsdvd/provider_id=PROVIDER
          /lsdvd/track/ix=1
          /lsdvd/track/length=2874.667
          /lsdvd/track/vts_id=DVDVIDEO-VTS
          /lsdvd/track/chapter/ix=1
          /lsdvd/track/chapter/length=299.934
          /lsdvd/track/chapter/startcell=1
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=2
          /lsdvd/track/chapter/length=299.500
          /lsdvd/track/chapter/startcell=2
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=3
          /lsdvd/track/chapter/length=300.000
          /lsdvd/track/chapter/startcell=3
          [...]
          /lsdvd/track/chapter/ix=11
          /lsdvd/track/chapter/length=176.734
          /lsdvd/track/chapter/startcell=11
          /lsdvd/longest_track=1


          This is a LOT easier to process in a script than the default human-readable output of lsdvd. e.g. if I wanted just the chapter lengths in seconds:



          $ lsdvd -c -Ox /path/to/some/dvd.iso' | xml2 | 
          awk -F'[/=]' '$5 == "length" { print $6 }'
          299.934
          299.500
          300.000
          299.500
          300.000
          299.500
          299.500
          300.000
          299.500
          0.500
          176.734


          I'll also point out that if you're using awk, you don't need grep. So, if you want to use the human-readable output, your grep | grep | awk (as well as the len=${len:0:12} to strip the trailing comma) can be reduced to:



          lsdvd -c VIDEO_TS | awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }' | 
          while read len


          The field separator is defined here as either one-or-more spaces OR a comma.



          $ lsdvd -c '/path/to/some/dvd.iso' | 
          awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }'
          00:04:59.934
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:00:00.500
          00:02:56.734





          share|improve this answer


























          • Thank you very much. The result store here superuser.com/a/1472513/433898

            – user1855805
            yesterday














          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',
          autoActivateHeartbeat: false,
          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%2f535948%2fhow-to-sum-time-with-part-of-milliseconds-using-bash%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          sh can only do integer arithmetic so you have to use something else, like bc (or a language that can do non-integer arithmetic such as awk or perl).



          To use bc, you first have to convert the %H:%M:%S.%3N format to seconds (including the decimal fraction) and then pipe that into bc.



          For example:



          #!/bin/bash

          epoch='1970-01-01'

          len1='00:01:01.111'
          len2='00:02:02.222'

          # convert to seconds
          len1_s=$(date -u -d "$epoch $len1" '+%s.%3N')
          len2_s=$(date -u -d "$epoch $len2" '+%s.%3N')

          # add the seconds
          sum_s=$( echo "$len1_s + $len2_s" | bc )

          echo $len1_s + $len2_s = $sum_s

          # convert back to H:M:S.N
          sum=$(date -u -d "@$sum_s" '+%T.%3N')

          echo $len1 + $len2 = $sum


          Output:



          $ ./sum.sh 
          61.111 + 122.222 = 183.333
          00:01:01.111 + 00:02:02.222 = 00:03:03.333


          I'll leave implementing that in your while loop to you....but I will note that lsdvd has some useful output options that will give you the chapter lengths in seconds (so you don't need to convert them). Probably the most useful is the XML output option which can then be processed with xmlstarlet or xml2 to extract the chapter lengths.



          e.g. here's lsdvd's XML output converted to a line-oriented format (suitable for processing with awk or whatever) using xml2:



          It's an approx 48 minute video with 11 chapters, most of which are roughly 5 mins (300 seconds) long.



          $ lsdvd -c -Ox '/path/to/some/dvd.iso'  | xml2
          /lsdvd/device=/path/to/some/dvd.iso
          /lsdvd/title=TITLE
          /lsdvd/vmg_id=DVDVIDEO-VMG
          /lsdvd/provider_id=PROVIDER
          /lsdvd/track/ix=1
          /lsdvd/track/length=2874.667
          /lsdvd/track/vts_id=DVDVIDEO-VTS
          /lsdvd/track/chapter/ix=1
          /lsdvd/track/chapter/length=299.934
          /lsdvd/track/chapter/startcell=1
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=2
          /lsdvd/track/chapter/length=299.500
          /lsdvd/track/chapter/startcell=2
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=3
          /lsdvd/track/chapter/length=300.000
          /lsdvd/track/chapter/startcell=3
          [...]
          /lsdvd/track/chapter/ix=11
          /lsdvd/track/chapter/length=176.734
          /lsdvd/track/chapter/startcell=11
          /lsdvd/longest_track=1


          This is a LOT easier to process in a script than the default human-readable output of lsdvd. e.g. if I wanted just the chapter lengths in seconds:



          $ lsdvd -c -Ox /path/to/some/dvd.iso' | xml2 | 
          awk -F'[/=]' '$5 == "length" { print $6 }'
          299.934
          299.500
          300.000
          299.500
          300.000
          299.500
          299.500
          300.000
          299.500
          0.500
          176.734


          I'll also point out that if you're using awk, you don't need grep. So, if you want to use the human-readable output, your grep | grep | awk (as well as the len=${len:0:12} to strip the trailing comma) can be reduced to:



          lsdvd -c VIDEO_TS | awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }' | 
          while read len


          The field separator is defined here as either one-or-more spaces OR a comma.



          $ lsdvd -c '/path/to/some/dvd.iso' | 
          awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }'
          00:04:59.934
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:00:00.500
          00:02:56.734





          share|improve this answer


























          • Thank you very much. The result store here superuser.com/a/1472513/433898

            – user1855805
            yesterday
















          2














          sh can only do integer arithmetic so you have to use something else, like bc (or a language that can do non-integer arithmetic such as awk or perl).



          To use bc, you first have to convert the %H:%M:%S.%3N format to seconds (including the decimal fraction) and then pipe that into bc.



          For example:



          #!/bin/bash

          epoch='1970-01-01'

          len1='00:01:01.111'
          len2='00:02:02.222'

          # convert to seconds
          len1_s=$(date -u -d "$epoch $len1" '+%s.%3N')
          len2_s=$(date -u -d "$epoch $len2" '+%s.%3N')

          # add the seconds
          sum_s=$( echo "$len1_s + $len2_s" | bc )

          echo $len1_s + $len2_s = $sum_s

          # convert back to H:M:S.N
          sum=$(date -u -d "@$sum_s" '+%T.%3N')

          echo $len1 + $len2 = $sum


          Output:



          $ ./sum.sh 
          61.111 + 122.222 = 183.333
          00:01:01.111 + 00:02:02.222 = 00:03:03.333


          I'll leave implementing that in your while loop to you....but I will note that lsdvd has some useful output options that will give you the chapter lengths in seconds (so you don't need to convert them). Probably the most useful is the XML output option which can then be processed with xmlstarlet or xml2 to extract the chapter lengths.



          e.g. here's lsdvd's XML output converted to a line-oriented format (suitable for processing with awk or whatever) using xml2:



          It's an approx 48 minute video with 11 chapters, most of which are roughly 5 mins (300 seconds) long.



          $ lsdvd -c -Ox '/path/to/some/dvd.iso'  | xml2
          /lsdvd/device=/path/to/some/dvd.iso
          /lsdvd/title=TITLE
          /lsdvd/vmg_id=DVDVIDEO-VMG
          /lsdvd/provider_id=PROVIDER
          /lsdvd/track/ix=1
          /lsdvd/track/length=2874.667
          /lsdvd/track/vts_id=DVDVIDEO-VTS
          /lsdvd/track/chapter/ix=1
          /lsdvd/track/chapter/length=299.934
          /lsdvd/track/chapter/startcell=1
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=2
          /lsdvd/track/chapter/length=299.500
          /lsdvd/track/chapter/startcell=2
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=3
          /lsdvd/track/chapter/length=300.000
          /lsdvd/track/chapter/startcell=3
          [...]
          /lsdvd/track/chapter/ix=11
          /lsdvd/track/chapter/length=176.734
          /lsdvd/track/chapter/startcell=11
          /lsdvd/longest_track=1


          This is a LOT easier to process in a script than the default human-readable output of lsdvd. e.g. if I wanted just the chapter lengths in seconds:



          $ lsdvd -c -Ox /path/to/some/dvd.iso' | xml2 | 
          awk -F'[/=]' '$5 == "length" { print $6 }'
          299.934
          299.500
          300.000
          299.500
          300.000
          299.500
          299.500
          300.000
          299.500
          0.500
          176.734


          I'll also point out that if you're using awk, you don't need grep. So, if you want to use the human-readable output, your grep | grep | awk (as well as the len=${len:0:12} to strip the trailing comma) can be reduced to:



          lsdvd -c VIDEO_TS | awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }' | 
          while read len


          The field separator is defined here as either one-or-more spaces OR a comma.



          $ lsdvd -c '/path/to/some/dvd.iso' | 
          awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }'
          00:04:59.934
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:00:00.500
          00:02:56.734





          share|improve this answer


























          • Thank you very much. The result store here superuser.com/a/1472513/433898

            – user1855805
            yesterday














          2












          2








          2







          sh can only do integer arithmetic so you have to use something else, like bc (or a language that can do non-integer arithmetic such as awk or perl).



          To use bc, you first have to convert the %H:%M:%S.%3N format to seconds (including the decimal fraction) and then pipe that into bc.



          For example:



          #!/bin/bash

          epoch='1970-01-01'

          len1='00:01:01.111'
          len2='00:02:02.222'

          # convert to seconds
          len1_s=$(date -u -d "$epoch $len1" '+%s.%3N')
          len2_s=$(date -u -d "$epoch $len2" '+%s.%3N')

          # add the seconds
          sum_s=$( echo "$len1_s + $len2_s" | bc )

          echo $len1_s + $len2_s = $sum_s

          # convert back to H:M:S.N
          sum=$(date -u -d "@$sum_s" '+%T.%3N')

          echo $len1 + $len2 = $sum


          Output:



          $ ./sum.sh 
          61.111 + 122.222 = 183.333
          00:01:01.111 + 00:02:02.222 = 00:03:03.333


          I'll leave implementing that in your while loop to you....but I will note that lsdvd has some useful output options that will give you the chapter lengths in seconds (so you don't need to convert them). Probably the most useful is the XML output option which can then be processed with xmlstarlet or xml2 to extract the chapter lengths.



          e.g. here's lsdvd's XML output converted to a line-oriented format (suitable for processing with awk or whatever) using xml2:



          It's an approx 48 minute video with 11 chapters, most of which are roughly 5 mins (300 seconds) long.



          $ lsdvd -c -Ox '/path/to/some/dvd.iso'  | xml2
          /lsdvd/device=/path/to/some/dvd.iso
          /lsdvd/title=TITLE
          /lsdvd/vmg_id=DVDVIDEO-VMG
          /lsdvd/provider_id=PROVIDER
          /lsdvd/track/ix=1
          /lsdvd/track/length=2874.667
          /lsdvd/track/vts_id=DVDVIDEO-VTS
          /lsdvd/track/chapter/ix=1
          /lsdvd/track/chapter/length=299.934
          /lsdvd/track/chapter/startcell=1
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=2
          /lsdvd/track/chapter/length=299.500
          /lsdvd/track/chapter/startcell=2
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=3
          /lsdvd/track/chapter/length=300.000
          /lsdvd/track/chapter/startcell=3
          [...]
          /lsdvd/track/chapter/ix=11
          /lsdvd/track/chapter/length=176.734
          /lsdvd/track/chapter/startcell=11
          /lsdvd/longest_track=1


          This is a LOT easier to process in a script than the default human-readable output of lsdvd. e.g. if I wanted just the chapter lengths in seconds:



          $ lsdvd -c -Ox /path/to/some/dvd.iso' | xml2 | 
          awk -F'[/=]' '$5 == "length" { print $6 }'
          299.934
          299.500
          300.000
          299.500
          300.000
          299.500
          299.500
          300.000
          299.500
          0.500
          176.734


          I'll also point out that if you're using awk, you don't need grep. So, if you want to use the human-readable output, your grep | grep | awk (as well as the len=${len:0:12} to strip the trailing comma) can be reduced to:



          lsdvd -c VIDEO_TS | awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }' | 
          while read len


          The field separator is defined here as either one-or-more spaces OR a comma.



          $ lsdvd -c '/path/to/some/dvd.iso' | 
          awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }'
          00:04:59.934
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:00:00.500
          00:02:56.734





          share|improve this answer













          sh can only do integer arithmetic so you have to use something else, like bc (or a language that can do non-integer arithmetic such as awk or perl).



          To use bc, you first have to convert the %H:%M:%S.%3N format to seconds (including the decimal fraction) and then pipe that into bc.



          For example:



          #!/bin/bash

          epoch='1970-01-01'

          len1='00:01:01.111'
          len2='00:02:02.222'

          # convert to seconds
          len1_s=$(date -u -d "$epoch $len1" '+%s.%3N')
          len2_s=$(date -u -d "$epoch $len2" '+%s.%3N')

          # add the seconds
          sum_s=$( echo "$len1_s + $len2_s" | bc )

          echo $len1_s + $len2_s = $sum_s

          # convert back to H:M:S.N
          sum=$(date -u -d "@$sum_s" '+%T.%3N')

          echo $len1 + $len2 = $sum


          Output:



          $ ./sum.sh 
          61.111 + 122.222 = 183.333
          00:01:01.111 + 00:02:02.222 = 00:03:03.333


          I'll leave implementing that in your while loop to you....but I will note that lsdvd has some useful output options that will give you the chapter lengths in seconds (so you don't need to convert them). Probably the most useful is the XML output option which can then be processed with xmlstarlet or xml2 to extract the chapter lengths.



          e.g. here's lsdvd's XML output converted to a line-oriented format (suitable for processing with awk or whatever) using xml2:



          It's an approx 48 minute video with 11 chapters, most of which are roughly 5 mins (300 seconds) long.



          $ lsdvd -c -Ox '/path/to/some/dvd.iso'  | xml2
          /lsdvd/device=/path/to/some/dvd.iso
          /lsdvd/title=TITLE
          /lsdvd/vmg_id=DVDVIDEO-VMG
          /lsdvd/provider_id=PROVIDER
          /lsdvd/track/ix=1
          /lsdvd/track/length=2874.667
          /lsdvd/track/vts_id=DVDVIDEO-VTS
          /lsdvd/track/chapter/ix=1
          /lsdvd/track/chapter/length=299.934
          /lsdvd/track/chapter/startcell=1
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=2
          /lsdvd/track/chapter/length=299.500
          /lsdvd/track/chapter/startcell=2
          /lsdvd/track/chapter
          /lsdvd/track/chapter/ix=3
          /lsdvd/track/chapter/length=300.000
          /lsdvd/track/chapter/startcell=3
          [...]
          /lsdvd/track/chapter/ix=11
          /lsdvd/track/chapter/length=176.734
          /lsdvd/track/chapter/startcell=11
          /lsdvd/longest_track=1


          This is a LOT easier to process in a script than the default human-readable output of lsdvd. e.g. if I wanted just the chapter lengths in seconds:



          $ lsdvd -c -Ox /path/to/some/dvd.iso' | xml2 | 
          awk -F'[/=]' '$5 == "length" { print $6 }'
          299.934
          299.500
          300.000
          299.500
          300.000
          299.500
          299.500
          300.000
          299.500
          0.500
          176.734


          I'll also point out that if you're using awk, you don't need grep. So, if you want to use the human-readable output, your grep | grep | awk (as well as the len=${len:0:12} to strip the trailing comma) can be reduced to:



          lsdvd -c VIDEO_TS | awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }' | 
          while read len


          The field separator is defined here as either one-or-more spaces OR a comma.



          $ lsdvd -c '/path/to/some/dvd.iso' | 
          awk -F' +|,' '/Chapter:/ && /Length:/ { print $5 }'
          00:04:59.934
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:04:59.500
          00:05:00.000
          00:04:59.500
          00:00:00.500
          00:02:56.734






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          cascas

          41.4k4 gold badges59 silver badges111 bronze badges




          41.4k4 gold badges59 silver badges111 bronze badges
















          • Thank you very much. The result store here superuser.com/a/1472513/433898

            – user1855805
            yesterday



















          • Thank you very much. The result store here superuser.com/a/1472513/433898

            – user1855805
            yesterday

















          Thank you very much. The result store here superuser.com/a/1472513/433898

          – user1855805
          yesterday





          Thank you very much. The result store here superuser.com/a/1472513/433898

          – user1855805
          yesterday


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535948%2fhow-to-sum-time-with-part-of-milliseconds-using-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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...