在命令行上如何从第 n 个索引开始按升序排序

On command-line how to start sorting from nth index in ascending order

=> "ls" 命令始终按升序输出:

common_results /1_L_0.010293_O=3.4077_B=1_SR=1.1349_500/ test.txt

common_results/1_L_0.010588_O=0.24208_B=0_SR=0.70094_500/ test.txt

common_results/1_L_0.011283_O=1.6461_B=0_SR=0.86875_500/ test.txt

common_results/1_L_0.011446_O=2.9968_B=0_SR=0.74779_500/ test.txt

common_results/1_L_0.011487_O=8.5498_B=0_SR=0.84261_500/ test.txt

=> 是否可以 "ls" 从第 n 个索引点开始上升。例如,从第 29 个索引点开始,它将从 "_O="

旁边的字符开始上升

"ls"(更新结果。)

common_results/1_L_0.010588_O=0.24208_B=0_SR=0.70094_500/ test.txt

common_results /1_L_0.010293_O=3.4077_B=1_SR=1.1349_500/ test.txt

common_results/1_L_0.011446_O=2.9968_B=0_SR=0.74779_500/ test.txt

common_results/1_L_0.011487_O=8.5498_B=0_SR=0.84261_500/ test.txt

common_results/1_L_0.011283_O=1.6461_B=0_SR=0.86875_500/ test.txt

解析 ls 的输出并不总是一个好主意,但是,只要您了解后果(它可能充满各种奇妙的字符,例如空格或换行符,所有这些都会导致简单化假设失败)并且可以缓解问题,您可以通过 sort 传递文件名以获得您想要的效果:

pax> #   1         2         3         4
pax> #7890123456789012345678901234567890
pax> #                        V
pax> echo '
common_results/1_L_0.010293_O=3.4077_B=1_SR=1.1349_500/test.txt
common_results/1_L_0.010588_O=0.24208_B=0_SR=0.70094_500/test.txt
common_results/1_L_0.011283_O=1.6461_B=0_SR=0.86875_500/test.txt
common_results/1_L_0.011446_O=2.9968_B=0_SR=0.74779_500/test.txt
common_results/1_L_0.011487_O=8.5498_B=0_SR=0.84261_500/test.txt' | sort  -k1.31

common_results/1_L_0.010588_O=0.24208_B=0_SR=0.70094_500/test.txt
common_results/1_L_0.011283_O=1.6461_B=0_SR=0.86875_500/test.txt
common_results/1_L_0.011446_O=2.9968_B=0_SR=0.74779_500/test.txt
common_results/1_L_0.010293_O=3.4077_B=1_SR=1.1349_500/test.txt
common_results/1_L_0.011487_O=8.5498_B=0_SR=0.84261_500/test.txt

根据第一个字段的第 31 个字符(均基于 1)对输出进行排序,即 O=.

之后的字符的位置

如果数字可能大于或等于 10,您可能还想为 sort 使用 -n 数字标记。否则,27.1828 将被视为小于 3.14159