Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie help

Status
Not open for further replies.

Murugs

Technical User
Jun 24, 2002
549
US
Being a beginner in awk I need the following steps to be performed for text file
The text file contains

Increment 1

MAXIMUM 305.6

MINIMUM 31.62


N O D E O U T P U T




THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET LOAD_NODE

NODE FOOT- U1 U2 U3 UR1 UR2
NOTE

59 -1.4877E-03 0.000 -0.3494 0.000 1.2497E-02
203 -7.3659E-03 0.000 -1.116 0.000 1.6711E-02


Increment 2 and some values etc..
Increment 3 and corresponding values...

I need the MAXIMUM (here 305.6) and U3 values (-0.3494 and -1.116) from the above text file.

I need to extract these 3 values from this text file for the final increment value i.e I do not need the values for Increment 1
instead need values for the final increment no in the text file. (If a text file has data for 34 increments I need the values only for 34th increment and not for others)



Regards
MP
 
Murugs:

From what you've described in your data file: Both MINIMUM and MAXIMUM are field 1 and the corresponding value is field 2; Just read the file getting the last instance:

awk '
{
if($1 == "MAXIMUM")
maxval=$2
if($1 == "MINIMUM")
minval=$2
} END { print minval; print maxval } ' input.file
 
I understood the problem differently and here is my solution.
Code:
{
  if ($1 == "Increment") flg = 0
  else if ($1 == "NOTE") {
    flg = 1
    f4max = -999999
  }
  if (flg && NF>0 && $4 > f4max) f4max = $4
}
END { print f4max }
Hope this helps. CaKiwi
 
Thanks for the reply. I have posted one more question in the similar format and I have trouble in understanding you being a beginner. Pls respond to that so that I will better understand and pardon me for my ignorance.

Thanks
Murugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top