Skip to main content
added 424 characters in body
Source Link
echo 'process1    00:03:34
process2    00:00:35
process3    00:12:34'|awk '{print $2}'|xargs -I {} gdate -d "1970-01-01 {} UTC" +%s|jq -sr 'add|(.|strftime("%H:%M:%S"))'
00:16:43

extract the elements from the second column

awk '{print $2}'

pass each line's timestamp into gdate command to convert it to a UTC timestamp

xargs -I {} gdate -d "1970-01-01 {} UTC" +%s

Convert it to a numerical array using jq, then sum them up to get the total number of seconds, and finally convert it to the "%H:%M:%S" format using strftime:

jq -sr 'add|(.|strftime("%H:%M:%S"))'
echo 'process1    00:03:34
process2    00:00:35
process3    00:12:34'|awk '{print $2}'|xargs -I {} gdate -d "1970-01-01 {} UTC" +%s|jq -sr 'add|(.|strftime("%H:%M:%S"))'
00:16:43
echo 'process1    00:03:34
process2    00:00:35
process3    00:12:34'|awk '{print $2}'|xargs -I {} gdate -d "1970-01-01 {} UTC" +%s|jq -sr 'add|(.|strftime("%H:%M:%S"))'
00:16:43

extract the elements from the second column

awk '{print $2}'

pass each line's timestamp into gdate command to convert it to a UTC timestamp

xargs -I {} gdate -d "1970-01-01 {} UTC" +%s

Convert it to a numerical array using jq, then sum them up to get the total number of seconds, and finally convert it to the "%H:%M:%S" format using strftime:

jq -sr 'add|(.|strftime("%H:%M:%S"))'
Source Link

echo 'process1    00:03:34
process2    00:00:35
process3    00:12:34'|awk '{print $2}'|xargs -I {} gdate -d "1970-01-01 {} UTC" +%s|jq -sr 'add|(.|strftime("%H:%M:%S"))'
00:16:43