Article View: alt.lang.awk
Article #8Re: tolower() function?
From: tbates
Date: Thu, 21 Jan 1993 21:55
Date: Thu, 21 Jan 1993 21:55
54 lines
1917 bytes
1917 bytes
In article <EMCOOP.93Jan19111755@bcars148.bnr.ca>, emcoop@bnr.ca (hume smith) writes:
> In article <1993Jan19.152725.3510@trentu.ca> ccgwt@trentu.ca (Grant Totten) writes:
>
> Is there a 'covert the line to lower case' function available in awk?
> Or even 'convert to lower case except for the first character of the
> line' function?
>
> gawk has tolower
> --
> Hume Smith My name is little Bongo
> hume.smith@acadiau.ca I sing my little song-go
> emcoop@bnr.ca Rhymes are hard to think of
> Except for made-up words like "flong-go"
Quoting "The AWK Programming Language",
"The cleanest way to do case conversion in awk is with an array that
maps each letter...it's better to use...tr"
I often use tr for this very reason. For example:
echo "HeLlO, wOrLd!" | tr [:upper:] [:lower]
This gives you:
hello, world!
To use tr from awk:
#!/bin/awk -f
{
"echo "$0" | tr [:upper:] [:lower:]" | getline
print
}
To skip the first character:
#!/bin/awk -f
{
start_of_line=$0
rest_of_line=$0
start_of_line=substr($0,1,1)
rest_of_line=substr($0,2)
"echo " rest_of_line " | tr [:upper:] [:lower:]" | getline rest_of_line
print start_of_line rest_of_line
}
Sincerely,
Tom
--
Tom Bates
IBM Austin
Technical Details
Message-ID:
<C184vr.p5q@austin.ibm.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!tbatesReferences:
<1993Jan19.152725.3510@trentu.ca> <EMCOOP.93Jan19111755@bcars148.bnr.ca>Show Full Headers
Complete Article Headers
Newsgroups: alt.lang.awk Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!tbates From: tbates@austin.ibm.com () Subject: Re: tolower() function? Originator: tbates@rama.austin.ibm.com Sender: news@austin.ibm.com (News id) Message-ID: <C184vr.p5q@austin.ibm.com> Date: Thu, 21 Jan 1993 21:55:03 GMT References: <1993Jan19.152725.3510@trentu.ca> <EMCOOP.93Jan19111755@bcars148.bnr.ca> Organization: IBM Austin Lines: 55