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

scripting

Status
Not open for further replies.

ledong

Technical User
Joined
Oct 3, 2000
Messages
9
Location
US
Hi all,
I need to write a script to bring up a smallest and a largest numbers on a file but i could not figure out. Please help. I am new in this game.

TYVM

Dong Le
ledong@hotmail.com [sig][/sig]
 
What does the file look like? How big is it?

If it has 1 number per line, you could sort it in ascending order, and then take the first line (smallest) and last line (largest) .. i.e. (in ksh)

[tt]
SMALLEST=`sort myfile | head -1`
LARGEST=`sort myfile | tail -1`
[/tt]

You'll need to check the syntax of sort, but that's one possible way.

Greg.
[sig][/sig]
 
Hi Greg,

Sorry I forgot.
There were 5 numbers per line and total 12 line on the file.
Please help.

Thanks
Dong
[sig][/sig]
 
Dong,

try posting this to the awk forum. [sig]<p>Ged Jones<br><a href= > </a><br>Top man[/sig]
 
cat $file | awk '{printf (&quot;%05d\n%05d\n%05d\n%05d\n%05d\n&quot;,$1,$2,$3,$4,$5);}' | sort

then do a head and tail on it ... :)

the %05d is digit (ie number) of 5 digits (minimum) with 0's preceding it if it is not 5 digits big ...

if you have numbers greater than 5 digits increase it, if you have number less than 5, then you can reduce it.

Hmm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top