+-
Linux shell排序文件根据第二列?
我有这样一个文件:

FirstName, FamilyName, Address, PhoneNumber

我如何按FamilyName对其进行排序?

最佳答案
如果这是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

点击查看更多相关文章

转载注明原文:Linux shell排序文件根据第二列? - 乐贴网