Read in numbers from a datafile

Hi,

I want to be able to read numbers from many files which have the same general form as follows:

C3H8              4.032258004031807E-002
 Phi =    1.000000E+00 Tau =       5.749E+00
 sL0  =    3.805542E+01 dL0 =    1.514926E-02
 Tb  =    2.328291E+03 Tu =  3.450E+02 Alpha =    8.743165E-02
 Mixture Visco. =    1.977164E-04 g/cm-s

What I would like to do is read the values of sL0, dL0, Tb, Tu and then write them out in another file as column data. For example,

sL0       dL0       Tb         Tu
3.805542E+01   1.514926E-02    2.328291E+03  3.450E+02

what I have so far is

awk '/Sl/{Sl=$3}/Tb/{Tb=$3}END{print Sl, Tb}' DILAT.DAT

I don't know how to pick Tu and dL0, as these variables are not at the start of the line.

Thanks!

You can try:

awk 'BEGIN{ print "sL0", "dL0", "Tb","Tu"}/sL0.*dL0/{sL0=$3;dL0=$6}/Tb.*Tu/{ print sL0, dL0, $3,$6}'
1 Like

Hi, how can I use a similar code to the one given above to read the value next to 'Thermal thickness' in the following data? i.e. how can awk deal with the space character?

Sl  =    3.480633E+01 Thermal thickness =    2.163022E-02

Thanks

Assuming that you are interested in the last field of rows containing "Thermal thickness"

awk '/Thermal thickness/ { Tt = $NF }'
1 Like