有没有办法让unix的sort
命令对不同位数的数字进行操作?如果我执行sort -n
,我会得到下面的示例数据输出:
pdvoq_shared_mma:voq_counters[0]/dropped_packets
pdvoq_shared_mma:voq_counters[10]/dropped_packets
pdvoq_shared_mma:voq_counters[11]/dropped_packets
pdvoq_shared_mma:voq_counters[1]/dropped_packets
pdvoq_shared_mma:voq_counters[2]/dropped_packets
pdvoq_shared_mma:voq_counters[3]/dropped_packets
pdvoq_shared_mma:voq_counters[4]/dropped_packets
pdvoq_shared_mma:voq_counters[5]/dropped_packets
pdvoq_shared_mma:voq_counters[6]/dropped_packets
pdvoq_shared_mma:voq_counters[7]/dropped_packets
pdvoq_shared_mma:voq_counters[8]/dropped_packets
pdvoq_shared_mma:voq_counters[9]/dropped_packets
但我真正想要的是
pdvoq_shared_mma:voq_counters[0]/dropped_packets
pdvoq_shared_mma:voq_counters[1]/dropped_packets
pdvoq_shared_mma:voq_counters[2]/dropped_packets
pdvoq_shared_mma:voq_counters[3]/dropped_packets
pdvoq_shared_mma:voq_counters[4]/dropped_packets
pdvoq_shared_mma:voq_counters[5]/dropped_packets
pdvoq_shared_mma:voq_counters[6]/dropped_packets
pdvoq_shared_mma:voq_counters[7]/dropped_packets
pdvoq_shared_mma:voq_counters[8]/dropped_packets
pdvoq_shared_mma:voq_counters[9]/dropped_packets
pdvoq_shared_mma:voq_counters[10]/dropped_packets
pdvoq_shared_mma:voq_counters[11]/dropped_packets
我当然可以想出如何在python或其他东西中解析这个,然后对提取的字段进行排序,但似乎UNIX已经解决了这类问题:)
1条答案
按热度按时间bxgwgixi1#
假设您的数据保存在data.txt文件中:
将产生你想要的输出。你需要GNU sort来完成这个。