Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash, extract string between two patterns

I have a text file that contains a snippet like this:

[#0] PROGRESS:Eval -- P values for  mu_sig-130-0 =  1
        CLs      = 0.0463722 +/- 0
        CLb      = 0.499991 +/- 0
        CLsplusb = 0.0231857 +/- 0

I would like to find the CLs line, and then print out just the number 0.0463722

Is there a way to do this via bash command line?

EDIT: the numbers can change from file to file, but the rest of that line stays the same.

like image 894
user788171 Avatar asked Mar 06 '26 21:03

user788171


1 Answers

awk '$1 == "CLs", $0 = $3'

Result

0.0463722
like image 78
Zombo Avatar answered Mar 08 '26 10:03

Zombo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!