Linux command sum numbers in a file


Example we have file stream.m3u8 with content

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:16
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:15,
#EXT-X-BYTERANGE:1071412@0
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1069720@1071412
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1052424@2141132
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1045844@3193556
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1064832@4239400
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1050356@5304232
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1021216@6354588
media.ts
#EXTINF:15,
#EXT-X-BYTERANGE:1085512@7375804
media.ts
...

How to calculate sum of duration of all segments

cat stream.m3u8|grep EXTINF:|awk -F '[:,]' '{sum+=$2} END {print sum}'

Recent search terms:

  • headers_module apache 2 2

Leave a Reply