[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible incorrect behaviour of AWK
From: |
Andrew J. Schorr |
Subject: |
Re: Possible incorrect behaviour of AWK |
Date: |
Tue, 17 Mar 2020 11:12:44 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
On Tue, Mar 17, 2020 at 02:18:06PM -0000, Phil J FIsher wrote:
> $ LC_ALL=C awk --posix 'BEGIN {RS="^---$";ORS="\n\n"} {print $0,RS,NR}'
I think the problem here may be the anchor metacharacters. From the docs:
https://www.gnu.org/software/gawk/manual/html_node/gawk-split-records.html
NOTE: Remember that in `awk', the `^' and `$' anchor
metacharacters match the beginning and end of a _string_, and not
the beginning and end of a _line_. As a result, something like
`RS = "^[[:upper:]]"' can only match at the beginning of a file.
This is because `gawk' views the input file as one long string
that happens to contain newline characters. It is thus best to
avoid anchor metacharacters in the value of `RS'.
When you say "$", do you actually mean "\n", for example?
Regards,
Andy