0

I have few lines like below were I need to sort and print the lines based on variable:value

15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sum id:705 SignatureId : EDXGH  Events:1320 Time Taken By All Events:11 eps:12000.0 Process Time on Average (in ms) for each event:0.008333333333333333
15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sum id:231 SignatureId : EDXGH  Events:60 Time Taken By All Events:13 eps:6000.0 Process Time on Average (in ms) for each event:0.016666666666666666
15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sum id:644 SignatureId : EDXGH  Events:1320 Time Taken By All Events:909 eps:14666.666666666666 Process Time on Average (in ms) for each event:0.006818181818181818

I am trying to sort the lines based on "Time Taken By All Events:909" I am expecting to see the output as below

15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sum id:644 SignatureId : EDXGH  Events:1320 Time Taken By All Events:909 eps:14666.666666666666 Process Time on Average (in ms) for each event:0.006818181818181818
15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sumid:768 SignatureId : EDXGH Events:1320 Time Taken By All Events:13 eps:10153.846153846152 Process Time on Average (in ms) for each event:0.009848484848484848
15:16:31.640 [Executor task launch worker for task 85] INFO  IAME- Sum id:705 SignatureId : EDXGH  Events:1320 Time Taken By All Events:11 eps:12000.0 Process Time on Average (in ms) for each event:0.008333333333333333

Any help on how to get this using linux commands

1
  • Your input and output do not match. Commented Nov 24, 2021 at 17:56

2 Answers 2

2

This is the "decorate-sort-undecorate" pattern: it extracts the number you want to sort by, puts it at the front of the line, sorts, then removes the number

paste <(grep -oP 'Time Taken By All Events:\K\d+' file) file \
| sort -nr -k1,1 \
| cut -f2-

I assume every line contains the "time taken by all events" -- the paste output will be wrong if that assumption is false.


Same concept, different command to, now, filter and decorate:

perl -lne 'print "$1\t$_ file" if /Time Taken By All Events:(\d+)/' file \
| sort -nr -k1,1 \
| cut -f2-
Sign up to request clarification or add additional context in comments.

3 Comments

it contains some other unwanted lines as well
And how are those supposed to be sorted? Add all details into your question
I have other lines as well , but I need those lines which have the key word "Time Taken by" and those lines need to be sorted based on the value as updated
0

Another form of decorate-sort-undecorate:

sed -E 's/^(.*Time Taken By All Events:)([0-9]*)(.*)$/\2 \1\2\3/' file | sort -nr -k1,1 | sed -E 's/^([^[:space:]]* )(.*)/\2/'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.