shell – 根据第二列排序文件?

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/bash/390959.html

猜你在找的Bash相关文章