Search code examples
regexbashsox

Select value with regular expression


I have little knowledge of regular expressions, so I would like to know if you can only select the maximum amplitude value from this text returned by the sox program? In this case, for example, I would like to select only 0.712219

Samples read:           6615000
Length (seconds):     75.000000
Scaled by:         2147483647.0
Maximum amplitude:     0.712219
Minimum amplitude:    -0.805969
Midline amplitude:    -0.046875
Mean    norm:          0.009264
Mean    amplitude:    -0.000027
RMS     amplitude:     0.043011
Maximum delta:         0.734100
Minimum delta:         0.000000
Mean    delta:         0.008353
RMS     delta:         0.041470
Rough   frequency:         6767
Volume adjustment:        1.241

Solution

  • perl -nle 'm{Maximum amplitude:\s+(-?\d?\.?\d+)} and print $1' file
    

    0.712219

    This handles numbers with a negative sign and those with of without a digit followed by a decimal point and any number of digits.