Reading off values from a large file

Hi,

I have a large output file (star.log), with many lines of the following type

*** T vavg [K] unburnt:  723.187 / burnt: 2662.000

What I would like to do is pick the values 723.187 and 2662.000 and

What I've got so far is

awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF}END{print Tu, Tb}' star.log

However, this is picking values from just one line and I'm not sure why. Any help will be appreciated. Thanks!

Did you try :

awk '/unburnt:.*burnt:/{print $6, $NF}' star.log
1 Like

Great cheer! That works!

Your problem with this: awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF}END{print Tu, Tb}' star.log is that you do the print in the END section. This will just print one instance.
Change it to:

awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF;print Tu, Tb}' star.log
or just
awk '/unburnt:.*burnt:/{print $6, $NF}' star.log
1 Like

Hi,

just one more way to get the required output.

echo "*** T vavg [K] unburnt:  723.187 / burnt: 2662.000" | awk -F" " '{print$6" "$9}'

Output will be as follows.

723.187 2662.000

Just adding if we have file then following may help.

awk -F" " '{print$6" "$9}' star.log

Thanks,
R. Singh

---------- Post updated at 04:57 AM ---------- Previous update was at 04:10 AM ----------

1 more solution for same, may help.

echo "*** T vavg [K] unburnt:  723.187 / burnt: 2662.000" | sed 's/[[:alpha:]]//g;s/[[:punct:]]//g'

Output will be as follows.

723187   2662000

Thanks,
R. Singh

@RavinderSingh13
I guess OP has more than one line and need the search argument that you have removed.

Yes and... by the way the sed statement proposed by RavinderSingh13 also removed the dot in the numbers :

The expected :

723.187   2662.000

became

723187   2662000

which - i guess - is not the expected result.
if willing to use sed you may want to give a try to something like :

sed '/unburnt:.*burnt:/!d;s/[^ .0-9]*//g' infile
1 Like