Sort-command alphanumeric

By | May 8, 2012
Sort-command alphanumeric
If they all actually begin with “page$”
echo "page$1
page$20
page$2
page$10" | sort -k1.5n

Answer :

page$1
page$2
page$10
page$20
sort -k1.5n

-k to set the key

1.5 means that the 5th character of the 1st field is the start of the sort field
n means that this field is to be treated as numeric
Sample Commands
 

sort -k 5 -n

sort -t ":" -k 3 -n /etc/psswd

 

Leave a Reply

Your email address will not be published. Required fields are marked *