相关疑难解决方法(0)

如何使用bash脚本对与字符​​串+数字组合的字符串进行排序?

这是我要排序的数据。但是sort将数字处理为字符串,数据没有按我预期的那样排序。

/home/files/profile1
/home/files/profile10
/home/files/profile11
/home/files/profile12
/home/files/profile14
/home/files/profile15
/home/files/profile16
/home/files/profile2
/home /files/profile3
/home/files/profile4
/home/files/profile5
/home/files/profile6
/home/files/profile7
/home/files/profile8
/home/files/profile9

我想把这个排序,

/home/files/profile1
/home/files/profile2
/home/files/profile3
/home/files/profile4
/home/files/profile5
/home/files/profile6
/home/files/profile7
/home/files/profile8
/home /files/profile9
/home/files/profile10
/home/files/profile11
/home/files/profile12
/home/files/profile14
/home/files/profile15
/home/files/profile16

bash脚本有什么好方法吗?我不能在这里使用 ruby​​ 或 python 脚本。

bash shell-script text-processing sort

27
推荐指数
3
解决办法
3万
查看次数

当某些行是个位数而其他行是两位数时,如何对文件进行数字排序?

例如假设我在文本文件中有以下内容myfile.txt

Schwifty1
Schwifty2
Schwifty3
Schwifty4
Schwifty5
Schwifty6
Schwifty7
Schwifty8
Schwifty9
Schwifty10
... ect ect ect...
Schwifty20
Schwifty21
... ect ect ect...
Schwifty30
Schwifty31
Run Code Online (Sandbox Code Playgroud)

sort在此文件上使用将返回类似以下内容:

Schwifty1
Schwifty10
Schwifty11
.........
Schwifty2
Schwifty20
Schwifty21
.........
Schwifty30
Schwifty31
Schwifty32
..........
Run Code Online (Sandbox Code Playgroud)

我希望它实际上是基于末尾附加的数字的数字。有什么办法可以使用排序功能来完成此任务吗?

sort

6
推荐指数
1
解决办法
3065
查看次数

标签 统计

sort ×2

bash ×1

shell-script ×1

text-processing ×1