Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently I am running a command like this, to get the most requested content:

grep "17\/Jul\/2011" other_vhosts_access.log | awk '{print $8}' | sort | uniq -c | sort -nr

I want to now see the user agent strings, but the problem is they include several spaces. Here is a typical log file line. The UA is the last section delimited by quotation marks:

example.com:80 [ip] - - [17/Jul/2011:23:59:59 +0100] "GET [url] HTTP/1.1" 200 6449 "[referer]" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30"

Is there a better tool than awk for this?

share|improve this question
up vote 8 down vote accepted

If that format is consistent and the field is really wrapped in double quotes you can use either awk or cut with " as the field delimiter:

awk -F\" '{print $6}'


cut -d\" -f 6
share|improve this answer
perl -ne 'if(/"([^"]+)"$/){$ua{$1}++;} END{for(keys %ua){print "$ua{$_} $_\n"}}' \
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.