I have list of some mp3's:
song 1.mp3
song 2.mp3
.
.
.
song 349.mp3
I can see their bitrate via right mouse button -> Properties -> Audio/Video, but also I can check it using the terminal command
file "song 1.mp3"
I'd like to find out which bitrate from my list is most frequently used, so I thought it would be nicely done via shell i.e. shell script.
I would lose too much time if I typed
file "song 1.mp3"; file "song 2.mp3"; ... ; file "song 349.mp3"
So, my question is :
Can we pass arguments line by line from some text file to shell function? An additional problem is that my song names contain spaces.
Assuming your list of files is one filename per line, the
xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.If you prefer to use a shell function
You can use a shell glob like
*.mp3
to select all files in the current directory that end with.mp3
. This will automagically take care of spaces and other special characters as well.On an mp3 I tested, I got output like this for
file
:You said you are interested in the bit rate, i.e.
56 kbps
here. We can usegrep
to extract only that part of the output with a regular expression like'\d+\s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are
sort
anduniq
:On one of my music folders, the output looked like below. First number is the file count, second the bit rate: