Reading off values from a large file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading off values from a large file
# 1  
Old 10-14-2013
Reading off values from a large file

Hi,

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

Code:
*** 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

Code:
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!
# 2  
Old 10-14-2013
Did you try :
Code:
awk '/unburnt:.*burnt:/{print $6, $NF}' star.log

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 10-14-2013
Great cheer! That works!
# 4  
Old 10-14-2013
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:
Code:
awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF;print Tu, Tb}' star.log
or just
awk '/unburnt:.*burnt:/{print $6, $NF}' star.log

This User Gave Thanks to Jotne For This Post:
# 5  
Old 10-14-2013
Hi,

just one more way to get the required output.

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

Output will be as follows.

Code:
723.187 2662.000


Just adding if we have file then following may help.

Code:
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.

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

Output will be as follows.


Code:
723187   2662000


Thanks,
R. Singh

Last edited by RavinderSingh13; 10-14-2013 at 06:12 AM.. Reason: added a 1 more solution
# 6  
Old 10-14-2013
@RavinderSingh13
I guess OP has more than one line and need the search argument that you have removed.
# 7  
Old 10-14-2013
Quote:
Originally Posted by Jotne
@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 :
Code:
723.187   2662.000

became
Code:
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 :
Code:
sed '/unburnt:.*burnt:/!d;s/[^ .0-9]*//g' infile

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

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reoccuring peak values in large data file and print the line..

Hi i have some large data files that contain several fields and rows the data in a field have a numeric value that is in a sine wave pattern what i would like todo is locate each peak and pick the highest value and print that complete line. the data looks something like this it is field nr4 which... (4 Replies)
Discussion started by: ninjaunx
4 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Reading and Comparing values of file

Hi gurus.. Am reading a file, counting number of lines and storing it in a variable. Then am passing that variable into If loop for comparision, if the number of lines are greater than 1000 it should split a file if not it should send the file name to archive folder.. but when i execute the... (4 Replies)
Discussion started by: azherkn3
4 Replies

5. Shell Programming and Scripting

reading the values from a file in C Shell for loop

Hi All, I need small help on for loop syntax in C shell. How can we read the values from a file (line by line) through C shell loop. For Ex: $Cat file1 data1 data2 data3 data4 $ I have to print those values in a variable and have to perform some steps... Can anyone help on... (2 Replies)
Discussion started by: raghu.iv85
2 Replies

6. Shell Programming and Scripting

Reading values from a file

Hi I have a file in the following format AFUE 0. AOXI 0. VFUE 100.0 VOXI 274.601 TFUE 298. TOXI 2229.544 TMAX 2400. What I want to do is write a bash script, that use either perl/awk or sed to read the number after VFUE and VOXI (which is 100.0 and... (1 Reply)
Discussion started by: lost.identity
1 Replies

7. Shell Programming and Scripting

Reading values from a file using DB2 SQL

I have some alphbetical codes in that (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

8. Shell Programming and Scripting

Reading large file, awk and cut

Hello all, I have 2 files, the first (indexFile1) contains start offset and length for each record inside the second file. The second file can be very large, each actual record start offset and length is defined by the entry in indexFile1. Since there are no records separators wc-l returns 0 for... (1 Reply)
Discussion started by: gio001
1 Replies

9. UNIX for Dummies Questions & Answers

Reading from a file and assigning values

HI I have something like this in a file ABC = 1 DEF = 2 GHI = 3 JKL = 4 MNO = 5 QRS = 6 TUV = 7 I need to assign ABC to V_abc (that is to a variable) GHI to V_ghi (that is to another variable) TUV to say V_tuv ... (6 Replies)
Discussion started by: ssuresh1999
6 Replies
Login or Register to Ask a Question