case insensitive split() 
Author Message
 case insensitive split()

hello,

how do i make split(s, a, RE) to have RE be case insensitive?
i need this, because i wrote this little grep script, that
looks through my mail spool, and prints From: and Subject
lines in a fancy way. i was not sure if "From:" field must've
been case-sensitive. also, when printing From: lines, i did
not want to print "From:", so i did the following:

header is array of lines contained in message header

if (tolower(header[j]) ~ /^from:/)
{
    gotfrom = 1;
    split(header[j], a, "^[Ff][Rr][Oo][Mm]: *"); # this seems UGLY
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    fromfield = a[2];
    printf(">%s<\n", fromfield);

    break;

Quote:
}

i would appreciate the "dude, why the hell are you doing it
this way" comments as well. however, even if this is the
wrong way to do it, i would still like to know the answer
to my original question :)

thanks,

denis



Sat, 14 Feb 2004 06:56:53 GMT  
 case insensitive split()


Quote:
>hello,

>how do i make split(s, a, RE) to have RE be case insensitive?

BEGIN { IGNORECASE = 1 }

should do the trick in gawk. Of course setting the value to something
else than 0 would also do it.



Sat, 14 Feb 2004 08:18:28 GMT  
 case insensitive split()

Quote:
> how do i make split(s, a, RE) to have RE be case insensitive?

In gawk, you just have to set the IGNORECASE variable to 1.

--
BBP



Sat, 14 Feb 2004 08:21:58 GMT  
 case insensitive split()


Quote:
>hello,

>how do i make split(s, a, RE) to have RE be case insensitive?
>i need this, because i wrote this little grep script, that
>looks through my mail spool, and prints From: and Subject
>lines in a fancy way. i was not sure if "From:" field must've
>been case-sensitive. also, when printing From: lines, i did
>not want to print "From:", so i did the following:

>header is array of lines contained in message header

>if (tolower(header[j]) ~ /^from:/)
>{
>    gotfrom = 1;
>    split(header[j], a, "^[Ff][Rr][Oo][Mm]: *"); # this seems UGLY
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    fromfield = a[2];
>    printf(">%s<\n", fromfield);

>    break;
>}

>i would appreciate the "dude, why the hell are you doing it
>this way" comments as well. however, even if this is the
>wrong way to do it, i would still like to know the answer
>to my original question :)

>thanks,

>denis

Hello Denis,

This should be equivalent to what you wrote, I think :-

if (tolower(header[j]) ~ /^from:/) {
  gotfrom = 1
  fromfield = substr(header[j],6)
  printf ">%s<\n", fromfield
  break

Quote:
}

Not tested.

I assume you need variables fromfield and gotfrom and that you need the
break (I could certainly use one).

"The break statement causes an exit from the immediately enclosing while
or for or do." TAPL

You can use either semicolons or newlines to separate statements, you
don't need both. Also printf does not require its arguments to be
enclosed in parentheses.

Hope this helps.
--
Alan Linton



Sun, 15 Feb 2004 03:28:58 GMT  
 case insensitive split()
Alan,




[snip]

| if (tolower(header[j]) ~ /^from:/) {
|   gotfrom = 1
|   fromfield = substr(header[j],6)
|   printf ">%s<\n", fromfield
|   break
| }

thanks, this sounds like a better way to do what i want,
although i think IGNORECASE=1 works.
i think your way sounds more portable.

| I assume you need variables fromfield and gotfrom and that you need
the
| break (I could certainly use one).

yeah...

| You can use either semicolons or newlines to separate statements,
you
| don't need both. Also printf does not require its arguments to be
| enclosed in parentheses.

well, one of the things i like awk for is that it is syntactically
similar to C :) i suppose to people who know awk, my little snippets
look
stupid, because of the things i mentioned, but it is more natural for
me
to lay out code like this :)

denis



Mon, 16 Feb 2004 00:30:42 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Case Sensitivity (actually case-insensitive file-systems)

2. Case-insensitive pattern matching for HTML processing

3. last field of array/case insensitive pattern matching query

4. Database search case-insensitive?

5. case insensitive search

6. Case insensitive select

7. QBE Case Insensitive

8. Case Insensitive COMPARE

9. Case-insensitive Forth

10. Case insensitive PARSE?

11. case insensitive match with regexp object

12. case-insensitive string compare?

 

 
Powered by phpBB® Forum Software