gpt4 book ai didi

linux - Bash shell - 按第二个字母对单词列表进行排序?

转载 作者:IT王子 更新时间:2023-10-29 00:54:40 27 4
gpt4 key购买 nike

我需要按第二个字母的字母顺序对单词列表进行排序,但我似乎想不出一种方法来做到这一点。

未分类:

smokelessly
toelike
arsenous
malabar
antiperspirant
hock
nibbing
paleographically
goon

排序:

malabar
paleographically
nibbing
smokelessly
antiperspirant
hock
toelike
goon
arsenous

我读过有关 sort 命令的内容,但它似乎没有让我执行此操作的功能?

最佳答案

sort -kX.Y 是你的 friend ! X 指列,Y 指字符。

$ sort -k1.2 file
malabar
paleographically
nibbing
smokelessly
antiperspirant
hock
toelike
goon
arsenous

如果你想定义排序的最后一个位置,你可以使用

sort -k1.2,Z file

来自人工排序:

-k, --key=KEYDEF

sort via a key; KEYDEF gives location and type

KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position in the field; both are origin 1, and the stop position defaults to the line's end. If neither -t nor -b is in effect, characters in a field are counted from the beginning of the preceding whitespace. OPTS is one or more single-letter ordering options [bdfgiMhnRrV], which override global ordering options for that key. If no key is given, use the entire line as the key.

关于linux - Bash shell - 按第二个字母对单词列表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23382422/

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