J
J
Jalart2015-11-20 14:26:30
*nix-like systems
Jalart, 2015-11-20 14:26:30

How to limit the output of log analysis results?

To analyze the activity of IP addresses on the site in the console, use the following command:

cat /var/logs/sitename.access.log | grep '13:55' | awk '{print $1}' | sort -k 1,1M -k 2n | uniq -c | sort -nr

But all rows sorted in descending order are displayed. And you need to display the first 10 lines of sorting results and stop.
head or tail are not appropriate because you need to parse the entire log file.
Of course, you can drive everything into a script (save it to a temporary file and apply head / tail to it), but you need the efficiency of work right in the console, so that by substituting values, you get the result immediately, without unnecessary script editing steps and unnecessary garbage.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Heizenberg, 2015-11-20
@Jalart

Put at the end | head

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question