|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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: Code:
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, Code:
sL0 dL0 Tb Tu 3.805542E+01 1.514926E-02 2.328291E+03 3.450E+02 what I have so far is Code:
awk '/Sl/{Sl=$3}/Tb/{Tb=$3}END{print Sl, Tb}' DILAT.DATI don't know how to pick Tu and dL0, as these variables are not at the start of the line. Thanks! |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
You can try: Code:
awk 'BEGIN{ print "sL0", "dL0", "Tb","Tu"}/sL0.*dL0/{sL0=$3;dL0=$6}/Tb.*Tu/{ print sL0, dL0, $3,$6}' |
| The Following User Says Thank You to user8 For This Useful Post: | ||
lost.identity (02-15-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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? Code:
Sl = 3.480633E+01 Thermal thickness = 2.163022E-02 Thanks |
|
#4
|
|||
|
|||
|
Assuming that you are interested in the last field of rows containing "Thermal thickness" Code:
awk '/Thermal thickness/ { Tt = $NF }' |
| The Following User Says Thank You to user8 For This Useful Post: | ||
lost.identity (02-23-2013) | ||
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, read data |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sorting the datafile in an order given in second datafile | CAch | Shell Programming and Scripting | 2 | 09-07-2011 07:42 AM |
| read numbers from file and output which numbers belongs to which range | thepurple | Shell Programming and Scripting | 6 | 05-13-2009 06:07 AM |
| Reversing numbers in a datafile of rows and columns | mattings | Shell Programming and Scripting | 16 | 04-17-2009 08:03 AM |
| How do I read/find/replace fields in a csv datafile? | MrCarter | UNIX for Dummies Questions & Answers | 9 | 06-20-2008 10:15 AM |
| Combine a datafile with Master datafile, emergent! | onthetopo | Shell Programming and Scripting | 6 | 05-12-2007 06:36 AM |
|
|