The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-25-2008
giorgos193 giorgos193 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 17
Help with awk - read from file

Hi,

I've got a file like the following:

Code:
Starting to process segment 0 (and symmetry related segments)
	Number of (cancelled) singularities: 0
	Number of (cancelled) negative numerators: 0
	Segment 0: 5.49secs
Starting to process segment 1 (and symmetry related segments)
	Number of (cancelled) singularities: 0
	Number of (cancelled) negative numerators: 0
	Segment 1: 10.01secs
Starting to process segment 2 (and symmetry related segments)
	Number of (cancelled) singularities: 0
	Number of (cancelled) negative numerators: 0
	Segment 2: 7.82secs
Starting to process segment 3 (and symmetry related segments)
	Number of (cancelled) singularities: 0
	Number of (cancelled) negative numerators: 0
	Segment 3: 5.31secs
... and I would like to extract the information about the time. I would like to read the file, save the time (of each line) to a variable, remove the suffix secs and then add it to the previous value. The result will be the total time....

I tried many things but none of them works... In case it helps, the last one I tried was

Code:
 
TIME="`awk '/Segment/ {print $3%secs + $TIME} ' log.txt`"

echo $TIME
It's a silly solution, but I think it may convey what I want to do....
I suspect that it has something to do with reading each line separetely, but I can't figure it out...

Thanks a lot in advance...