如果这是UNIX:
sort -k 2 file.txt
您可以使用多个-k标志对多个列进行排序。例如,按姓氏排序,然后按名字排序:
sort -k 2,2 -k 1,1 file.txt
来自“man sort”的相关选项:
-k,–key=POS1[,POS2]
start a key at POS1,end it at POS2 (origin 1)
POS is F[.C][OPTS],where F is the field number and C the character position in the field. OPTS is one or more single-letter ordering options,which override global ordering options for that key. If no key is given,use the entire line as the key.
-t,–field-separator=SEP
use SEP instead of non-blank to blank transition