News for hackers. Stuff that matters.
Re:Getting Unique Counts From a Log File by joshbaptiste on Saturday June 22, 2013 @08:28PM (#5925732)
It amazes me at work how many people just violate UUOC/UUOG

ie..

  cat file | grep bar | awk '{ print $1 }' | sort | uniq
which can simply be

  awk '/bar/ { print $1 | "sort -u"}' file
Re:Getting Unique Counts From a Log File by casca on Saturday June 22, 2013 @09:17PM (#5925866)
I've done this for single-use pipelines when built up because the nature of the data is unfamiliar. It usually starts with

   cat file | less
and then

   cat file | grep bar | less
and then

   cat file | grep bar | awk '{ print $1 }' | less
and so on.

But if it's going to be used more than once then it does seem odd to have the unnecessary commands. Maybe "advanced" awk (beyond print $1) is unknown to people?

Re:Getting Unique Counts From a Log File by ibotty on Sunday June 23, 2013 @05:12AM (#5926784)
if you are only doing 'print $1' you should be using cut. but whatever.
Re:Getting Unique Counts From a Log File by gpapilion on Saturday June 22, 2013 @08:40PM (#5925767)
Its a balance of clarity, vs efficiency. Also, I chose uniq over sort -u, for the -c option.

That being said, point well made.

Re:Getting Unique Counts From a Log File by e12e on Saturday June 22, 2013 @10:47PM (#5926060)
Well, I often do:

    cat some.log | awk '/regexp/ { print $2}' | sort| uniq
Then tweak that line to get what I want, then change it to:

    zcat some.log*| ...