Unix Scripting Compare Integers

I have a file with the following:

87565
82155
102656
151
162

I want to write korn shell script that will read each line in a loop and remove any number that has less than 5 digits, e.g., 151 and 152.

thank you,

Keoki:confused:

Your title is incorrect. You do not want to compare integers, you want to compare string lengths.

while read n
do
  [ ${#n} -ge 5 ] && printf "%s\n" "$n"
done < FILE

For a large file, it will be faster with awk, sed or even grep:

awk 'length >= 5' FILE

awk '/...../' FILE

sed -n '/...../p' FILE

grep '.....' FILE

Try...

grep ..... file

Thank you very much, your code does exactly what I want.

I guess was I not articulating my problem corretly so I had no luck searching the newsgroups.

Yeah, ..... will work for 5 digits/letters/zebras.. but just in case you want to get them from a file that has letters or other stuff..

egrep "[0-9]{5,}" FILE

I know it looks different, but I like to search for *exactly* what I am searching for, maybe I am just weird. :slight_smile: