bug-gawk
[Top][All Lists]
Advanced

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

Re: RS='.^' apparently ignores the RS setting


From: arnold
Subject: Re: RS='.^' apparently ignores the RS setting
Date: Tue, 13 Jul 2021 05:46:54 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Ed Morton <mortoneccc@comcast.net> wrote:

> So I read 
> https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_09
>  
> which I thought was saying you could use any character before the `^` 
> and it wouldn't match which was supported by this test:
>
>      $ printf 'ax^b\nax^b\n' | awk 'BEGIN{RS="x^"}{print NR, $0}'
>      1 ax^b
>      ax^b
>
> but then I can't explain this where gawk is apparently completely 
> ignoring the RS setting:
>
>      $ printf 'a.^b\na.^b\n' | awk 'BEGIN{RS=".^"}{print NR, $0}'
>      1 a.^b
>      2 a.^b
>
> Is that a bug?

No. ^ and $ are always metacharacters in EREs, even if that means
you can create nonsense regexps. You have to escape them to get
them to be treated literally:

$ printf 'ax^b\nax^b\n' | ./gawk 'BEGIN{RS="x\\^"}{print NR, $0}'
1 a
2 b
a
3 b

$ printf 'a.^b\na.^b\n' | ./gawk 'BEGIN{RS=".\\^"}{print NR, $0}'
1 a
2 b
a
3 b

HTH,

Arnold



reply via email to

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