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.
Assuming the expected output is approximate (i.e. the second column in the example output could be different):
awk -F_ '{
print $0, b[$3, $1]++
}' OFS=_ infile |
sort -t_ -k1,1 -k4,4n -k3n |
cut -d_ -f1-3
I didn't tested the script thoroughly though ...
精彩评论