Home > Archive > AWK > May 2006 > regex issue
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| mickey 2006-05-11, 9:56 pm |
| I have lines in a file which either end with a ':' or start with 'Char'.
I have a script that needs to distinguish between the two. When I give
if($0 ~ /:$/) {...} # doesn't work.
However,
if($0 !~ /^Char/) {...} #works fine.
What am I doing wrong here? I am using latest version of gawk.
Thanks,
-M
| |
| Ed Morton 2006-05-12, 3:56 am |
| mickey wrote:
> I have lines in a file which either end with a ':' or start with 'Char'.
> I have a script that needs to distinguish between the two. When I give
>
> if($0 ~ /:$/) {...} # doesn't work.
>
> However,
>
> if($0 !~ /^Char/) {...} #works fine.
>
> What am I doing wrong here? I am using latest version of gawk.
>
> Thanks,
> -M
Your input file probably has control characters or other white space
after the ":"s, like those pesky control-Ms that Windows leaves lying
around. On UNIX, cat -v would show control chars.
Ed.
| |
| mickey 2006-05-12, 3:56 am |
| Ed Morton wrote:
> mickey wrote:
>
>
>
> Your input file probably has control characters or other white space
> after the ":"s, like those pesky control-Ms that Windows leaves lying
> around. On UNIX, cat -v would show control chars.
>
> Ed.
Thanks. That was pretty stupid of me.
-M
| |
| martin cohen 2006-05-12, 6:57 pm |
| mickey wrote:
> Ed Morton wrote:
>
>
>
> Thanks. That was pretty stupid of me.
>
> -M
I've done that too. It's almost a reflex to add
sub(/\r$/, "")
after each line is read.
|
|
|
|
|