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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using nwak

Status
Not open for further replies.

ledong

Technical User
Oct 3, 2000
9
US
Hi all,
I need help to write a script to get a largest and a lowest number on a file with several fields on a line separate by column.
Please help.
TYVM

Dong
ledong@hotmail.com
 
Dong we need an example, is your file something like this: -

1234 4567 7890 0101 9999
2345 5678 8901 0202 8888
1010 2020 3030 4040 7777
0987 7654 4321 4444 6666



Ged Jones

Top man
 
Hi Ged,
Yes it is similar
Thanks

Dong
 
This awk program tests for both queries in one pass
and prints the results.

If your data is delimited by commas or colons, add
a BEGIN statement to the first line thus:

awk 'BEGIN { FS = "," }


awk '

FILENAME == "infile" {
for ( i=1 ; i<= NF ; i++ )
if ( $i >= largest ) largest = $i
}

FILENAME == &quot;infile&quot; {
for ( i=1 ; i<= NF ; i++ )
if ( $i <= lowest ) lowest = $i

} END { print &quot;&quot;
print &quot;Largest number is : &quot;largest
print &quot;Lowest number is : &quot;lowest }' infile infile




# Input test file listed below:


-.12345 1.2345 4.5678 -.003567 9.9876
12.5678 4.3498 7.8934 11.96215 -.2345
02.2543 3.1256 5.1234 -.000147 -.0003


Hope this helps!



flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top