[ale] sed head scratcher

Ed Cashin ecashin at noserose.net
Tue Aug 4 15:34:56 EDT 2009


On Tue, Aug 4, 2009 at 3:10 PM, Richard Bronosky<Richard at bronosky.com> wrote:
> That's pretty good. However, you are possibly altering the field
> separator (replacing spaces with tabs) and certainly loosing any
> fields greater than 3. This version changes field 2 and only field 2.
>
> cat /etc/hosts | awk '{$2=tolower($2); print}'

Nice!  I often forget that $2 isn't a copy of the second field but the
same one that's in $0.

Incidentally, there was a fun piece of pedantry that would regularly appear
on UNIX programming/sysadmin newsgroups in the nineties: UUoC,
which I see is mentioned in wikipedia:

  http://en.wikipedia.org/wiki/Cat_%28Unix%29#Useless_use_of_cat

I've never cared one way or another, and I often use cat when I don't
need to, but this example made me feel nostalgic.

I guess that might not be obvious to everyone.  It's because the
example below is functionally equivalent but uses no "cat" process:

  awk '{$2=tolower($2); print}' /etc/hosts

I'm sure Bronosky is well aware of that, though, and I would not
say this form is superior.  It's just interesting to me that folks used
to get flamed about this on usenet.

-- 
  Ed Cashin <ecashin at noserose.net>


More information about the Ale mailing list