Re: Generic way for replacing whitespaces with newlines
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 09/12/04
- Next message: nyetsky: "Motif"
- Previous message: Barry Margolin: "Re: grep and man pages"
- In reply to: Kenny McCormack: "Re: Generic way for replacing whitespaces with newlines"
- Next in thread: Chris F.A. Johnson: "Re: Generic way for replacing whitespaces with newlines"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 12 Sep 2004 11:10:07 -0500
Kenny McCormack wrote:
> In article <svadnZA05Pxy-dncRVn-pg@comcast.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
>
>>
>>Kenny McCormack wrote:
>><snip>
>>
>>>c) Since modern versions of awk (i.e., gawk, tawk) have built-in sorting (*),
>>>you can save a command and a pipe:
>>>
>>>awk -vdom="$MYLOCALDOMAIN"" '/^(domain|search)/ && $0 !~ dom {for (i=2;
>>>i <= NF ; i++) {zoo[$i]}} END {for (i in zoo) print i}' /etc/resolv.conf | xargs
>>>
>>>(*) In the distributed version of gawk, you have to set the environment
>>>variable "WHINY_USERS" in order for this to work.
>>
>>Tell me you're kidding!
>>
>> Ed.
>
>
> Nope. No joke. Observe:
>
> % gawk 'BEGIN {split("the quick brown fox jumps over the lazy dog",T);for (i in T) x[T[i]];for (i in x) print i}'
> fox
> quick
> over
> brown
> the
> jumps
> lazy
> dog
> % setenv WHINY_USERS
> % gawk 'BEGIN {split("the quick brown fox jumps over the lazy dog",T);for (i in T) x[T[i]];for (i in x) print i}'
> brown
> dog
> fox
> jumps
> lazy
> over
> quick
> the
> %
>
Unbelievable. Since we're getting into specific gawk details, I'm
setting followups to comp.lang.awk as I'd like to learn a little more
about this and that variable isn't mentioned in the gawk documentation
(http://www.gnu.org/software/gawk/manual/gawk.html).
Do you know:
a) Why "WHINY_USERS" was picked as the variable name?
b) Where is it documented?
c) Why was a variable chosen to implement this extremely useful
functionality rather than some language constauct (argument or "in"
extension, or...)?
d) Is there a way to specify that the sorting should be numeric instead
of alphabetical?
e) Can anyone explain the blank line at the start of the output in the
second example below?
eg1:
$ gawk 'BEGIN {split("10 1 2 3",T);for (i in T) x[T[i]];for (i in x)
print i}'
1
10
2
3
-----------
eg2:
$ gawk 'BEGIN {split("10 1 20 3",T);for (i in T) x[T[i]];for (i in x)
print i}'
1
10
20
3
------------
The above was produced with gawk 3.1.3 under Cygwin on Windows XP.
Regards,
Ed.
- Next message: nyetsky: "Motif"
- Previous message: Barry Margolin: "Re: grep and man pages"
- In reply to: Kenny McCormack: "Re: Generic way for replacing whitespaces with newlines"
- Next in thread: Chris F.A. Johnson: "Re: Generic way for replacing whitespaces with newlines"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|