public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Pandu Poluan <pandu@poluan.info>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] is a nice "place" :-D
Date: Tue, 17 May 2011 17:43:22 +0700	[thread overview]
Message-ID: <BANLkTi=Zp3tQzqH2bcpWwxcYZxHhS1H+4Q@mail.gmail.com> (raw)
In-Reply-To: <20110517082537.27317958@digimed.co.uk>

On 2011-05-17, Neil Bothwick <neil@digimed.co.uk> wrote:
> On Tue, 17 May 2011 01:33:39 +0200, Alan McKinnon wrote:
>
>> grep "GET /Tmp/Linux/G" | /var/log/apache2/access_log | grep-v <myip> |
>> \ awk '{print $1}' | sort | uniq | wc
>>
>> In true grand Unix tradition you cannot get quicker, dirtier or more
>> effective than that
>>
>
> awk does pattern matching, o you can ditch the grep stage and use
>
>  awk '! /myip/ {print $1}'
>
> You could use awk to search for the GET patterns too, not only saving yet
> another process, but making sure that no one else, including you next
> month, can work out what the command is supposed to do.
>

Meh, me forgetting what an awk snippet do? Never!

sed ... now that's a wholly different story :-P

> sort -u would save having a separate process for uniq, but I've no idea
> if it's faster. It's only worth using sort -u if you would use uniq with
> no arguments.
>

And you can actually do the 'uniq' or '-u' function within awk. Quite
easily, in fact.

Here's a sample of awk doing uniq:

awk '!x[$1]++ { print $1 }'

Benefit? It doesn't care if the non-unique lines are one-after-another
or spread all over the text. The above snippet prints only the first
occurence. Combine that with a test for match:

awk '!x[$1]++ && $0 ~ /awesome_regex_pattern/ {print $1}'

then with a test for negated match

awk '!x[$1]++ && $0 ~ /awesome_regex_pattern/ && $0 !~
/more_awesome_regex/ {print $1}'

Rgds,
--
Pandu E Poluan - IT Optimizer
My website: http://pandu.poluan.info/



  reply	other threads:[~2011-05-17 10:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-16 23:10 [gentoo-user] is a nice "place" :-D Felix Miata
2011-05-16 23:33 ` Alan McKinnon
2011-05-17  0:36   ` Willie Wong
2011-05-17  0:38   ` Felix Miata
2011-05-17  7:25   ` Neil Bothwick
2011-05-17 10:43     ` Pandu Poluan [this message]
2011-05-17 13:10       ` Juan Diego Tascón
2011-05-17 13:36         ` Alex Schuster
2011-05-17 13:51           ` Juan Diego Tascón
2011-05-17 14:34           ` Pandu Poluan
2011-05-17 17:38       ` Stroller
2011-05-18 10:17         ` Neil Bothwick
2011-05-18 19:03           ` Alan McKinnon
2011-05-18 20:04             ` Neil Bothwick
2011-05-18 20:15             ` Alan Mackenzie
2011-05-18 20:28               ` Alan McKinnon
2011-05-19 19:01                 ` Walter Dnes
2011-05-17 14:30   ` David Haller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=Zp3tQzqH2bcpWwxcYZxHhS1H+4Q@mail.gmail.com' \
    --to=pandu@poluan.info \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox