按照序号排序
A_xyz_01
B_mdd_01
A_djk_02
A_jfc_03
B_dmk_01
A_bcd_01
B_csd_02
B_dlf_03
A_jhf_02
B_dld_02
我希望根据 seq 编号(每行的最后两位数字)对这些行进行排序,最大 seq 为 03,在 03 之后,我需要相同开关 id 的 seq 01(A、B 行中的第一个字符) :
A_xyz_01
A_djk_02
A_jfc_03
A_bcd_01
A_jhf_02
B_dmk_01
B_csd_02
B_dlf_03
B_mdd_01
B_dld_02
上面的列表实际上是 ls 命令的输出。 我有来自不同交换机(A、B、C)的文件。它们的第三个字段是序列号。对于每个文件,我需要使用文件名做其他事情。 但这应该一次完成一个开关,我也需要按顺序执行(考虑第三个字段)。如果序列是最大的,我需要将文件与 01 作为序列,但与前面的01序列文件。需要重复此步骤,直到同一交换机的所有文件都结束。
A_xyz_01
B_mdd_01
A_djk_02
A_jfc_03
B_dmk_01
A_bcd_01
B_csd_02
B_dlf_03
A_jhf_02
B_dld_02
I want this lines to be sorted like below according to the seq number (the last two digits of each line) max seq is 03 and after 03 i need the seq 01 for the same switch id(first character in the line A,B):
A_xyz_01
A_djk_02
A_jfc_03
A_bcd_01
A_jhf_02
B_dmk_01
B_csd_02
B_dlf_03
B_mdd_01
B_dld_02
the above list is actually the output of ls command.
i have files comeing from different switches(A,B,C).they have the sequence number as the third field.for each and every file i need to take the name of the ile do something else.
but this should be done one switch at a time that too i need to do it in sequential order (considering the third field).if the sequence is maximum i need to have the file with 01 as as the sequence but a different file from the earlier 01 sequence file.This step need to be repeated untill all the files of the same switch are over.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设预期输出是近似的(即示例输出中的第二列可能不同):
但我没有彻底测试脚本......
Assuming the expected output is approximate (i.e. the second column in the example output could be different):
I didn't tested the script thoroughly though ...