当名称是实数时,是否可以按数字对文件进行排序?
Is it possibly to sort files numerically when names are real numbers?
我有一个文件,其名称是实数,包括正数和负数。
我需要文件的数字顺序,比如 -1.0、-0.5、0.0、0.5、1.0 .... 来制作 animation from the files
我试过了
ls -v1 -- *.pgm
但结果是
0.000000.pgm
0.080000.pgm
0.160000.pgm
0.240000.pgm
0.320000.pgm
0.400000.pgm
0.480000.pgm
0.560000.pgm
0.640000.pgm
0.720000.pgm
0.800000.pgm
0.880000.pgm
0.960000.pgm
1.040000.pgm
1.120000.pgm
1.200000.pgm
1.280000.pgm
1.360000.pgm
1.440000.pgm
1.520000.pgm
1.600000.pgm
1.680000.pgm
1.760000.pgm
1.840000.pgm
1.920000.pgm
2.000000.pgm
-0.080000.pgm
-0.160000.pgm
-0.240000.pgm
-0.320000.pgm
-0.400000.pgm
-0.480000.pgm
-0.560000.pgm
-0.640000.pgm
-0.720000.pgm
-0.800000.pgm
-0.880000.pgm
-0.960000.pgm
-1.040000.pgm
-1.120000.pgm
-1.200000.pgm
-1.280000.pgm
-1.360000.pgm
-1.440000.pgm
-1.520000.pgm
-1.600000.pgm
-1.680000.pgm
-1.760000.pgm
-1.840000.pgm
-1.920000.pgm
-2.000000.pgm
我该怎么做?
您正在寻找sort -g
“一般数字排序”
mapfile -t sorted_files < <(printf '%s\n' *.pgm | sort -g)
declare -p sorted_files
我有一个文件,其名称是实数,包括正数和负数。 我需要文件的数字顺序,比如 -1.0、-0.5、0.0、0.5、1.0 .... 来制作 animation from the files
我试过了
ls -v1 -- *.pgm
但结果是
0.000000.pgm
0.080000.pgm
0.160000.pgm
0.240000.pgm
0.320000.pgm
0.400000.pgm
0.480000.pgm
0.560000.pgm
0.640000.pgm
0.720000.pgm
0.800000.pgm
0.880000.pgm
0.960000.pgm
1.040000.pgm
1.120000.pgm
1.200000.pgm
1.280000.pgm
1.360000.pgm
1.440000.pgm
1.520000.pgm
1.600000.pgm
1.680000.pgm
1.760000.pgm
1.840000.pgm
1.920000.pgm
2.000000.pgm
-0.080000.pgm
-0.160000.pgm
-0.240000.pgm
-0.320000.pgm
-0.400000.pgm
-0.480000.pgm
-0.560000.pgm
-0.640000.pgm
-0.720000.pgm
-0.800000.pgm
-0.880000.pgm
-0.960000.pgm
-1.040000.pgm
-1.120000.pgm
-1.200000.pgm
-1.280000.pgm
-1.360000.pgm
-1.440000.pgm
-1.520000.pgm
-1.600000.pgm
-1.680000.pgm
-1.760000.pgm
-1.840000.pgm
-1.920000.pgm
-2.000000.pgm
我该怎么做?
您正在寻找sort -g
“一般数字排序”
mapfile -t sorted_files < <(printf '%s\n' *.pgm | sort -g)
declare -p sorted_files