Read in numbers from a datafile | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Read in numbers from a datafile

Shell Programming and Scripting


Tags
awk, read data

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
lost.identity lost.identity is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 27 May 2014, 11:56 AM EDT
Posts: 57
Thanks: 46
Thanked 1 Time in 1 Post
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.DAT

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

Thanks!
Sponsored Links
    #2  
Old 02-15-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
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  
Old 02-20-2013
lost.identity lost.identity is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 27 May 2014, 11:56 AM EDT
Posts: 57
Thanks: 46
Thanked 1 Time in 1 Post
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  
Old 02-20-2013
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 06:01 PM.