在包含一些性能信息的日志文件中,我想根据每行中写入的经过时间(实时)按递减顺序对行进行排序。例如:
Operation1 cpu-time = 10 real-time = 4 malloc = 1006
Operation2 cpu-time = 12 real-time = 5 malloc = 1002
// other info1 (without time or memory measurments)
Operation3 cpu-time = 9 real-time = 10 malloc = 1003
// other info2 (without time or memory measurments)
输出应该是这样的(按实时降序排序):
Operation3 cpu-time = 9 real-time = 10 malloc = 1003
Operation2 cpu-time = 12 real-time = 5 malloc = 1002
Operation1 cpu-time = 10 real-time = 4 malloc = 1006
// other info1 (without time or memory measurments)
// other info2 (without time or memory measurments)
请注意,不必要的行已移至文件末尾
答案 0 :(得分:3)
使用sort
:
sort -rn -k7,7
n
- 数字排序
r
- 反向
-k7,7
- 仅使用第7个字段进行排序(字段默认用空格分隔)