cascading pipes in awk
Ralph Finch
rfinch at caldwr.UUCP
Fri May 26 01:12:20 AEST 1989
In article <813 at manta.NOSC.MIL>, psm at manta.NOSC.MIL (Scot Mcintosh) writes:
> Is there a way to cascade pipes in awk? I'm trying to do something
> like the following:
> { print | "tr [a-z] [A-Z]" | <<other stuff that will manipulate the
> now-upper-case text >>
> }
>
> Any other suggestions to accomplish the same thing would be
> appreciated.
I'm also frustrated that awk doesn't allow the use of Unix utilities
inside of awk.
I had a similar problem that Scot did (only I wanted to go from upper
to lower case). Here was my solution:
name_up="UPPERCASENAME"
# create upper-to-lower table
for (i=65;i<=90;i++) {
up=sprintf("%c",i)
lw=sprintf("%c",i+32)
alpha[up]=lw
}
# preserve punctuation characters
for (i=32;i<=64;i++) {
c=sprintf("%c",i)
alpha[c]=c
}
for (i=91;i<=126;i++) {
c=sprintf("%c",i)
alpha[c]=c
}
# translate the name from upper-to-lower case
name_low=""
for (i=1; i<=length(name_up); i++)
name=name""alpha[substr(name_up,i,1)]
--
Ralph Finch
...ucbvax!ucdavis!caldwr!rfinch
More information about the Comp.unix.questions
mailing list