Reputation: 83
I have a line of data. It contains both words and numbers.It is
15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3
I need to extract the value -.33052537E+03 from this line.
Upvotes: 1
Views: 92
Reputation: 2681
If only single line is there, then assign this line to a variable.
var="15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3"
echo $var|awk '{print $3}'
If many lines are there, then insert those lines in a file, then
awk '{print $3}' file.txt
Upvotes: 0
Reputation: 113814
bash
$ read one two three rest <<<' 15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3'
$ echo "$three"
-.33052537E+03
awk
and bash
:$ awk '{print $3}' <<<' 15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3'
-.33052537E+03
sed
and bash
:$ sed 's/.*F= //; s/ E0=.*//' <<<' 15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3'
-.33052537E+03
grep
and bash
:$ grep -oP '(?<=F= ).*(?= E0=)' <<<' 15 F= -.33052537E+03 E0= -.33051414E+03 d E=.720942E-05 mag=24.6037:3'
-.33052537E+03
Upvotes: 2