help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

regexp not behaving as expected.


From: slipbits
Subject: regexp not behaving as expected.
Date: Mon, 18 Apr 2022 13:30:10 -0700
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0

GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1)
Win 7-64
cygwin

Eli Zaretskii;

I've got a problem with my use of regexp w/gawk and I can't seem to find out what I did wrong. When the first three characters on a line are "CC:" or "  CC:" it is sometimes recognized, and sometimes not recognized, and I can't figure out what I've done wrong.

The program is:

#! /bin/gawk  -f
{
   gensub(/\x00/, " ", "g");                       # replace regexp with " "
   if ($0 ~ /^([:space:]|\r)+$/) {                 # ignore blank line
      print "Recognized a blank line \"", $0, "\"";
   } else {
      if ($0 ~ /^([:space:]\r)*(Subject|Date|CC|BCC|From|To):/) {
         print "Recognized input \"", $0. "\"";
         getline;
      } else {
         print "Did not recognize input \"",$0, "\"";
      }
   }
}

My test input program is:

CC:
X@
 CC:
X@
CC:
X@

and my test output is:

Recognized input " CC:"
Did not recognize input "  CC: "
Did not recognize input " X@ "
Recognized input " CC:"
Did not recognize input " X@

I am including the source files.

Please, if you are not the right person to ask could you redirect me?

Thanks for the outstanding work that you are doing;

art

Attachment: x.txt
Description: Text document

Attachment: y
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]