![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can i read a non text file in unix - ELF-64 executable object file - IA64 | alexcol | UNIX for Advanced & Expert Users | 8 | 11-07-2008 08:56 AM |
| Post Shell programming: Question about source a file and read data from the file | ccwq | Shell Programming and Scripting | 3 | 08-04-2007 10:28 PM |
| Read words from file and create new file using K-shell. | bsrajirs | Shell Programming and Scripting | 4 | 06-01-2007 12:15 PM |
| Read xml file | ram2s2001 | Shell Programming and Scripting | 2 | 12-12-2005 12:20 AM |
| How to read specific lines in a bulk file using C file Programming | rajan_ka1 | High Level Programming | 10 | 11-10-2005 03:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 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
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... |
|
||||
|
For adding the values, is it enough if you get the sum at the end? Then awk is all you need:
Code:
awk '/Segment/ { gsub("secs",""); time += $3 } END { print time }' file.txt
Code:
awk '/Segment/ { gsub ("secs",""); time += $3; print $3, time } file.txt |
while read THISTIME SUMTIME; do
echo This time, we got $THISTIME
echo Sum so far is $SUMTIME
done
|
|
||||
|
I want to thank you all for you rapid response! All solutions are great! I really appreciate your effort!
@ era: I'm really impressed by your "sophisticated" solution! Thanks again!! |
| Sponsored Links | ||
|
|