Sort is often used to organize the output in asc/desc order.
Here are prominent options used with sort.
-n:sort in numeric order
-r:sort in reverse order
-t:Used to specify delimiter
-k:used to specify field number.
Lets explore the option with example.
Sort all users according to their names.
#sort -t ":" -k 1 /etc/passwd
Sort all users according to uid.
#sort -t ":" -k 3 -n /etc/passwd
Reverse sort above two queries .
#sort -t ":" -k 1 -r /etc/passwd
#sort -t ":" -k 3 -n -r /etc/passwd
No comments:
Post a Comment