Read in numbers from a datafile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read in numbers from a datafile
# 1  
Old 02-15-2013
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!
# 2  
Old 02-15-2013
You can try:
Code:
awk 'BEGIN{ print "sL0", "dL0", "Tb","Tu"}/sL0.*dL0/{sL0=$3;dL0=$6}/Tb.*Tu/{ print sL0, dL0, $3,$6}'

This User Gave Thanks to user8 For This Post:
# 3  
Old 02-20-2013
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
Assuming that you are interested in the last field of rows containing "Thermal thickness"
Code:
awk '/Thermal thickness/ { Tt = $NF }'

This User Gave Thanks to user8 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Read a file with decimal numbers in bash

Hello, I have the following script while read id fraction do sambamba -h -f bam -t 10 --subsampling-seed=50 -s $frac ${id}.bam -o ${id}.out.bam done < fraction.txt where fraction.txt has two columns (id,fraction) and 50 rows I am unable to run this as bash is not able to read the second... (2 Replies)
Discussion started by: nans
2 Replies

2. Programming

Read in numbers from console won't stop at newline.

Hello, I have snippet code from Lippman's <<C++ primer>>. The program is to convert regular decimal (0 ~ 15) numbers to basic hexdecimals. The instruction tells the program will execute by hitting newline at the end. When I tried to run the compiled program, hitting ENTER did not work as... (3 Replies)
Discussion started by: yifangt
3 Replies

3. Shell Programming and Scripting

Read numbers from file

I am trying to make a script to read marks from a file then find out how many of them are above 40 (passing marks). However my script is getting stuck at "read num". I dont understand whats the problem. Any help will be much appreciated. #!/bin/bash set -x count=0; countP=0; PASSMK=40... (6 Replies)
Discussion started by: vish6251
6 Replies

4. Shell Programming and Scripting

sorting the datafile in an order given in second datafile

Hi, I have two files: first input file is having 7-8 columns, and second data file is like I want to arrange my datafile1 in the order given in second data file, by comparing the seconddatafile with the second column of first file and print the entire line....also if any... (2 Replies)
Discussion started by: CAch
2 Replies

5. Shell Programming and Scripting

Help with addition of 2 numbers that are read from a file

I am trying to add free and used memory (so that i can compute percentage used)of remote nodes using shell script. I use the openssh-server,expect tool and ssh script. 1)login.txt (info of nodes): ip1|username|password ip2|username|password . . . 3)sshlogin.sh #!/bin/bash ... (1 Reply)
Discussion started by: marmik1903
1 Replies

6. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

7. Shell Programming and Scripting

Reversing numbers in a datafile of rows and columns

Hello, I've tried searching the forum for an answer to my question, but without any luck... I have a datafile looking simplified as follows: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 I want to reverse it by rearranging all the numbers from last to... (16 Replies)
Discussion started by: mattings
16 Replies

8. UNIX for Dummies Questions & Answers

How do I read/find/replace fields in a csv datafile?

hello. I'm somewhat a novice here so please be patient. My stumbling block when loading csvs into ORACLE tables is this: I need to read a csv datafile, check several fields in each line, and if any of stated fields contain A ZERO only then replace it with a null/blank character. I had a... (9 Replies)
Discussion started by: MrCarter
9 Replies

9. Shell Programming and Scripting

Combine a datafile with Master datafile, emergent!

Hi guys, my supervisor has asked me to solve the problem in 7 days, I've taken 3 days to think about it but couldn't figure out any idea. Please give me some thoughts with the following problem, I have index.database that has only index date: 1994 1995 1996 1997 1998 1999 I have... (6 Replies)
Discussion started by: onthetopo
6 Replies

10. Shell Programming and Scripting

selective positions from a datafile

Hi dear friends, Im writing a shell script which has to select the strings based on the position. but the problem is there is no field seperator. Normally a datafile contains 2000 records (lines) and each line is of size 500 charecters. I want to select the fields from all the lines which... (10 Replies)
Discussion started by: ganapati
10 Replies
Login or Register to Ask a Question