Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse and sum part of a field 1

Status
Not open for further replies.

400401

Technical User
Dec 5, 2008
1
CA
From the command line, I do:

ls /mnt/win_l/sound/sym_35_haffner_wam.ogg /mnt/win_k/ffl/ffl.1110.ogg /mnt/win_l/sound/sym_09_c_fs.ogg /mnt/win_l/sound/sym_36_linz_wam.ogg /mnt/win_k/ffl/ffl.1111.ogg /mnt/data1/sound/E10.Joy.ogg | sh /mnt/win_d/system/rh.ogg3

Here is what I want:

"/mnt/data1/sound/E10.Joy.ogg"... Playback length: 6m:00.129s
"/mnt/win_k/ffl/ffl.1110.ogg"... Playback length: 8m:14.193s
"/mnt/win_k/ffl/ffl.1111.ogg"... Playback length: 26m:44.046s
"/mnt/win_l/sound/sym_09_c_fs.ogg"... Playback length: 47m:47.478s
"/mnt/win_l/sound/sym_35_haffner_wam.ogg"... Playback length: 22m:20.395s
"/mnt/win_l/sound/sym_36_linz_wam.ogg"... Playback length: 29m:33.627s
Total 138 minutes


Here is what I get:

"/mnt/data1/sound/E10.Joy.ogg"... Playback length: 6m:00.129s
Total 6 minutes

"/mnt/win_k/ffl/ffl.1110.ogg"... Playback length: 8m:14.193s
Total 8 minutes

"/mnt/win_k/ffl/ffl.1111.ogg"... Playback length: 26m:44.046s
Total 26 minutes

"/mnt/win_l/sound/sym_09_c_fs.ogg"... Playback length: 47m:47.478s
Total 47 minutes

"/mnt/win_l/sound/sym_35_haffner_wam.ogg"... Playback length: 22m:20.395s
Total 22 minutes

"/mnt/win_l/sound/sym_36_linz_wam.ogg"... Playback length: 29m:33.627s
Total 29 minutes

The above is generated by:

#!/bin/bash
while read data; do
ogginfo $data | \
gawk ' BEGIN { RS = "Processing file" ; FS = "\n" }
{ print $1 " " $15 }
{ split ($15,a,/m:/)
sum +=substr(a[1],18,3 )+0 }
END {
print "Total "sum" minutes"
} '

I simply want to parse and sum the minutes only from field 15.
It seems the END statement is not working properly.

What am I doing wrong?

Thank you for your help.

Richard
 
while read data; do
ogginfo $data
done | \
gawk ' BEGIN ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
awk '$NF ~ /m:/ {TOT += substr($NF, 1, index($NF,"m:")-1)}; END {print TOT}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top