这是我要排序的数据。但是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 脚本。
例如假设我在文本文件中有以下内容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)
我希望它实际上是基于末尾附加的数字的数字。有什么办法可以使用排序功能来完成此任务吗?