I'm using Kubuntu to run SoX. I have the following code to get info from sound files:
for file in *.mp3; do echo -e '\n--------------------\n'$file'\n'; sox $file -n stats; done > stats.txt 2>&1 | tail -1
It produces output that looks like this:
--------------------
soundfile_name.mp3
DC offset -0.000287
Min level -0.585483
Max level 0.572299
Pk lev dB -4.65
RMS lev dB -19.55
RMS Pk dB -12.98
RMS Tr dB -78.44
Crest factor 5.56
Flat factor 0.00
Pk count 2
Bit-depth 29/29
Num samples 628k
Length s 14.237
Scale max 1.000000
Window s 0.050
Could someone amend the command to limit the output so that it looks like this?
--------------------
soundfile_name.mp3
Pk lev dB -4.65
RMS lev dB -19.55
RMS Pk dB -12.98
RMS Tr dB -78.44
thanks
CodePudding user response:
Given that the lines of interest have the word "dB" in common, you could filter SoX output with grep -w dB
:
for file in *.mp3; do echo -e '\n--------------------\n'$file'\n'; sox $file -n stats | grep -w dB; done > stats.txt 2>&1
Resulting content of stats.txt
:
--------------------
soundfile_name.mp3
Pk lev dB -4.65
RMS lev dB -19.55
RMS Pk dB -12.98
RMS Tr dB -78.44