hrexen hrexen - 5 months ago 9x
Bash Question

Converting ls output to an integer

I would like to extract a set of 2 digit numbers from the

output and be able to get the biggest and smallest numbers from it, for later usage.

I am doing this:
ls 14_data_*.log | egrep -o '[0-9]{2,2}' | head -1}
but the output is only sometimes in an ascending order and
of expectantly return wrong values. I tried converting it to an integer but hopeless.

What is returned by
and how can it be handled?


ls returns a list of files and directories in the current directory.

I don't know what you are upto but here is a solution to your problem using sort:

Descending order:

ls 14_data_*.log | egrep -o '[0-9]{2}' | sort -nr

Ascending order:

ls 14_data_*.log | egrep -o '[0-9]{2}' | sort -n