ignoring case in awk/nawk searches 
Author Message
 ignoring case in awk/nawk searches

Not having acces to gawk (with the IGNORCASE option), is there a way
to cause either awk or nawk to ignore case when doing a pattern search?

I'm using it to do a look up in a database of names and phone numbers.

so that when I give it the option 'steve'
it will math both 'Steve' and 'steve'.

Thanks for your help in advance.




Tue, 18 Jan 2000 03:00:00 GMT  
 ignoring case in awk/nawk searches

Quote:

>Not having acces to gawk (with the IGNORCASE option), is there a way
>to cause either awk or nawk to ignore case when doing a pattern search?

>I'm using it to do a look up in a database of names and phone numbers.

>so that when I give it the option 'steve'
>it will math both 'Steve' and 'steve'.

>Thanks for your help in advance.



Feed awk your search pattern in all uppercase, and use the toupper
function on the search field.  For example,

awk '{if ("STEVE" == toupper($1)) print}' datafile

--
Greg



Wed, 19 Jan 2000 03:00:00 GMT  
 ignoring case in awk/nawk searches

Quote:

> Not having acces to gawk (with the IGNORCASE option), is there a way
> to cause either awk or nawk to ignore case when doing a pattern search?

> I'm using it to do a look up in a database of names and phone numbers.

The toupper() function should work, as in

% echo -e "Williams \n Dangerfield \n Marx \n  \n" | \
  nawk '{if (toupper($0) ~ toupper("mArX)) print}'

Try it.

/Stephen Jungels



Wed, 19 Jan 2000 03:00:00 GMT  
 ignoring case in awk/nawk searches

Quote:


> >Not having acces to gawk (with the IGNORCASE option), is there a way
> >to cause either awk or nawk to ignore case when doing a pattern search?

> >I'm using it to do a look up in a database of names and phone numbers.

> >so that when I give it the option 'steve'
> >it will math both 'Steve' and 'steve'.

> >Thanks for your help in advance.


> Feed awk your search pattern in all uppercase, and use the toupper
> function on the search field.  For example,

> awk '{if ("STEVE" == toupper($1)) print}' datafile

Of course this assumes that your version of AWK or NAWK supports
toupper.  If not, you could write one up fairly easily, although it
would slowthings down quite a bit :)

/*****************************************************************
 * James Patrick Hutchinson | Systems Engineering & Architecture *

 ***********[ http://www.hutch.org/~james/resume.html ]***********/



Mon, 24 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. search on variable passed to awk /nawk

2. SUNOS NAWK - TOLOWER - In a print statement convert string to lower case

3. AWK-search the web quickly with Search Spaniel

4. awk, nawk & gawk

5. help for new user looking to use awk nawk or mawk

6. Limit for the Line handle by NAWK/AWK on SOLARIS 2.5.7

7. dynamic formatting not available in awk/oawk/nawk?

8. AWK/NAWK/GAWK questions !

9. How is this done in awk/nawk/gawk?

10. Whats nawk ( compare to awk ? )

11. printf in awk/nawk

12. Differences between awk/nawk/gawk/mawk

 

 
Powered by phpBB® Forum Software