加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – Bash shell – 按第二个字母排序单词列表?

发布时间:2020-12-14 01:26:30 所属栏目:Linux 来源:网络整理
导读:我需要按字母顺序排列第二个字母的单词列表,我似乎无法找到一种方法. 未排序: smokelesslytoelikearsenousmalabarantiperspiranthocknibbingpaleographicallygoon 排序方式: malabarpaleographicallynibbingsmokelesslyantiperspiranthocktoelikegoonarsen
我需要按字母顺序排列第二个字母的单词列表,我似乎无法找到一种方法.

未排序:

smokelessly
toelike
arsenous
malabar
antiperspirant
hock
nibbing
paleographically
goon

排序方式:

malabar
paleographically
nibbing
smokelessly
antiperspirant
hock
toelike
goon
arsenous

我已经阅读了sort命令,但它似乎没有让我这样做的功能?

解决方法

sort -kX.Y是你的朋友! 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读