sort

sort lines of text files

copy
31
3
sort -k 3bSort alphabetically, omitting the first and second fields and the blanks at the start of the third field. This uses a single key composed of the characters beginning at the start of the first nonblank character in field three and extending to the end of each line.

details |

copy
8
0
ls | sort -rReverse sort the current directory

details |

copy
6
0
sort -t : -k 5b,5 -k 3,3n /etc/passwdSort the password file on the fifth field and ignore any leading blanks. Sort lines with equal values in field five on the numeric user ID in field three. Fields are separated by :

details |

copy
5
1
route | sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort output of route by IP address.

details |

copy
5
0
sort -t : -k 2,2n -k 5.3,5.4Sort numerically on the second field and resolve ties by sorting alphabetically on the third and fourth characters of field five. Use `:' as the field delimiter.

details |

copy
5
1
sort -s -t ' ' -k 4.9n -k 4.5M -k 4.2n -k 4.14,4.21 /var/log/messages | sort -s -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n Sort a set of log files, primarily by IPv4 address and secondarily by time stamp. If two lines' primary and secondary keys are identical, output the lines in the same order that they were input.

details |

copy
5
0
sort -n -rSort in reverse numeric order

details |

copy
4
2
sort -t: -u +2 file.dataTo sort file.data on the third field and suppress the duplicates

details |

copy
3
0
ls */* | sort -t / -k 1,1R -k 2,2Shuffle a list of directories, but preserve the order of files within each directory. For instance, one could use this to generate a music playlist in which albums are shuffled but the songs of each album are played in order.

details |

copy
3
0
find src -type f -print0 | sort -z -f | xargs -0 etags --appendGenerate a tags file in case-insensitive sorted order. The use of `-print0', `-z', and `-0' in this case means that file names that contain blanks or other special characters are not broken up by the sort operation.

details |