我对-V
没有解决的排序有问题。我有一组结构良好的文件夹名称(如下所示sort -V
),我想做一个版本排序,但要识别浮点数(参见前两个条目)。有什么建议吗?
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_3_um_V_97.4_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_3_um_V_97_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_6_um_V_90_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_6_um_V_153_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_7_um_V_70_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_8_um_V_70_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_8_um_V_80_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_9_um_V_192_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_10_um_V_90_V
答案 0 :(得分:2)
如果要按浮点数排序,可以对第15个字段应用数字排序。
$ cat test.txt | sort -t _ -V -k 1,14 -k 15n
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_3_um_V_97_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_3_um_V_97.4_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_6_um_V_90_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_6_um_V_153_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_7_um_V_70_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_8_um_V_70_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_8_um_V_80_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_9_um_V_192_V
Xe_phi_3.5_eV_tOn_0.5_ns_tOff_20_ns_d_10_um_V_90_V