0

I have following file:

# cat /var/data/wlan_cells.log
"Tech 1" "57" "-67" "0"
"GUEST01" "52" "-69" "0"
"SWSGP01" "52" "-69" "0"
"GateAP" "100" "-39" "0"
"AP_9 test" "78" "-59" "0"
"surf" "13" "-85" "0"
"Tech 2" "18" "-83" "0"

How can I sort the lines by signal quality (second value)? Expected result:

# cat /var/data/wlan_cells.log
"GateAP" "100" "-39" "0"
"AP_9 test" "78" "-59" "0"
"Tech 1" "57" "-67" "0"
"GUEST01" "52" "-69" "0"
"SWSGP01" "52" "-69" "0"
"Tech 2" "18" "-83" "0"
"surf" "13" "-85" "0"

1 Answer 1

5

I'd use

sort -t\" -k4nr 

i.e. split to columns by ", use the fourth column, sort numerically in reversed order.

Sign up to request clarification or add additional context in comments.

3 Comments

Was expecting elegant solutions using AWK (which lends itself to these sort of things). But this is even better.
I love it, even if I don't understand it :)
That command splits every line of your log in columns. A new column is created everytime a " symbol is seen. So for example, in the first line the columns will be: a void column (because the first symbol met is a " The second column will be Tech 1. The third column will be a space. The fourth column will be 57. The sort command then sorts the fourth columns (the signal quality) of the log lines.

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.