grep | awk

Thursday, 24 February 2005 09:54
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
[personal profile] pne

Occasionally I see people writing little pipelines using both 'grep' and 'awk'... and it makes me wonder why you start two processes when one will do. (A bit like those who start pipelines with cat file | ... where <file ... will do just as well, and save one process.)

For example, why not replace ... | grep blurfle | awk '{ print $2 }' with ... | awk '/blurfle/ { print $2}'? Or replace ls -l | grep -v '^d' | awk '{total+=$5}END{print total}' with ls -l | awk '$1 !~ /^d/ {total+=$5} END {print total}'?

Especially since most of those recipes use a very simple argument to grep—typically a fixed string, or -v plus a fixed string—which would seem trivially convertible to part of an awk script even without having to learn the full awk language.

Re: defen[cs]e

Date: Thursday, 24 February 2005 15:40 (UTC)
From: [identity profile] ataltane.livejournal.com
Hmm, yes. God damn this increasing illiteracy. I used to be able to spell perfectly, and I probably gave unwanted advice to other people. So I probably deserve it :).

Anyway, whatever about the UK (where's that? the Ukraine? :), 'defence' is a perfectly fine Irish spelling. I occasionally use "European English" to include the Irish variety. This has the disadvantage that it sounds absurd, but the usual "British English" sounds absurd anyway, to the millions of English users outside of Britain but within ... these isles.

Re: defen[cs]e

Date: Thursday, 24 February 2005 15:41 (UTC)
From: [identity profile] ataltane.livejournal.com
Clarification: your spelling advice wasn't unwanted. No such implication intended!

Profile

pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
Philip Newton

June 2015

S M T W T F S
 12 3456
78910111213
14151617181920
2122232425 2627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sunday, 4 January 2026 13:36
Powered by Dreamwidth Studios