Skip to content
Advertisement

How to use awk regex sort by query string value?

I have a log file with example row:

JavaScript

The 7th column of each row looks like this:

JavaScript

Output is arranged according to the number of lines in decreasing order containing unique values of t.

Desired OUTPUT:

JavaScript

I am using awk but it is not giving desired output:

JavaScript

It outputs all columns after 7th which is not required. What am I doing wrong? Any suggestions please.

Advertisement

Answer

Using your 1 sample input line:

JavaScript

or if the rest of your input lines follow EXACTLY the format of that one line:

JavaScript

or entirely in awk:

JavaScript

or:

JavaScript

The above uses GNU awk 4.* for PROCINFO["sorted_in"] to sort the output. If you don’t have that, remove that line and pipe to sort -rn with appropriate args. You do not need the intermediate | sort | uniq -c either way.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement