regexp case-insensitive
Arnold Robbins
arnold at audiofax.com
Fri Nov 30 05:18:57 AEST 1990
In article <6801 at uceng.UC.EDU> schriste at uceng.UC.EDU (Steven V. Christensen) writes:
>Hi, I'm writing an AWK script which must search for the occurrance of
>user-specified text. Right now it is:
>
>/text/ {do something}
>
>But I need /text/ to be case insensitive. What do I need to do?
There are several options. The most portable is to put your awk program
into a pipeline on the other end of tr. Assuming a System V tr
tr '[A-Z]' '[a-z]' < data | awk '/text/ { stuff }'
# use tr A-Z a-z on a BSD system
where your text is in lower case. If you have the very latest at&t nawk
(available from the ATT Toolchest), you can use the tolower() built-in
function to map your data into one case, like so:
{ $0 = tolower($0) }
/text/ { stuff }
If you have or can get gnu awk, you set IGNORECASE=1 in a BEGIN block
or on the command line, and the regexp match will be done ignoring case.
Gnu awk also supports the tolower and toupper functions. If you don't
wish to use the tr example, those are your next best bet.
--
Arnold Robbins AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067 | exponentially in the
INTERNET: arnold at audiofax.com Phone: +1 404 933 7612 | number of children.
UUCP: emory!audfax!arnold Fax-box: +1 404 618 4581 | -- Miriam Robbins
More information about the Comp.unix.questions
mailing list