how to sort strings by length?

I'm trying to find the longest word in /usr/share/dict/words
The first thing I can think of is to sort the content by length then it would be easy to find out, but then i realize theres no option of sort to sort by length.
Could you guys please give me some help?:confused:

Some testing in Red Hat 5 EL ...

$ wc -l /usr/share/dict/words
483523 /usr/share/dict/words


$ awk '{ print length(), $0 | "sort -n" }'  /usr/share/dict/words

........
........
27 hydroxydesoxycorticosterone
29 cyclotrimethylenetrinitramine
29 trinitrophenylmethylnitramine
30 half-embracinghalf-embracingly
31 dichlorodiphenyltrichloroethane
45 pneumonoultramicroscopicsilicovolcanoconiosis

thank you very much Rubin, it works perfectly!
i have one more question, please:
so... length() in awk '{ pirnt $0 }'
will count the length of the entire line and print it out as line number?

Yes, ... it'll print out the number of all of the characters in the word.

ye... i guess i didnt ask my question clearly...
lets say... what if the line to be printed contains two or more words
what will length() do? my guess is the total number of characters of that line?
or in this case length() will not work properly?

Your guess is right, it'll print the total number of characters of the current line, including the whitespaces or any other character.
Refer to the awk man pages to learn what is & how length() function works.

ok i will
thank you very much mate!
cheers:D

Hi try this

awk '{ for(i=1; i<=NF;i++)  if(length(MaxWord) < length($i)) MaxWord=$i; } END { print MaxWord } '  filename

Regards

Ranjith