gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:26:14 27 4
gpt4 key购买 nike

我有一个这样的文件:

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 根据第二列排序文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4262650/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com