summing durations from a text file
So thanks to a little bit of pipe action and using mediainfo I was able to create a text file with the durations of recordings in the following format:
Code:
Duration : 13mn 16s I'd like to know just long all of this is. I was originally thinking of doing several sed commands creating additional text files from the 'h' 'mn' and 's' throughout, but I feel like that's creating more work for myself than it needs to be. I feel like awk should do this, but I have no idea how to work awk, so any help would be appreciated! |
There is almost certainly a more elegant way, but here's one that works, at least.
First, separate the numbers from their labels, so awk sees them as different fields. Assuming your file above is called "myfile": Code:
# sed -e 's/mn/ mn/' myfile | sed -e 's/s/ s/' | sed -e 's/h/ h/' > timefile Code:
# cat awk.tst If "h" is found in the 4th field, increment the variable hours by whatever number is in the third field. Then it looks for "mn" and "s" in the 6th field, incrementing the variables "minutes" and "seconds" appropriately. The END portion of an awk script is executed after all lines of the input file have been parsed. In this case, the END section simply prints out all the totals you've calculated. You can execute the awk file by running the following command: Code:
# awk -f awk.tst timefile |
Hooray, that took care of it.
Doing the adding myself, I have a folder full of 194 hours 43 minutes of recordings. And that demystifies some of AWK for me too. I appreciate the explanation. Many thanks lrtward! |
All times are GMT -5. The time now is 10:45 PM. |