bug-gawk
[Top][All Lists]
Advanced

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

Possible incorrect behaviour of AWK


From: Phil J FIsher
Subject: Possible incorrect behaviour of AWK
Date: Tue, 17 Mar 2020 14:18:06 -0000

Hi AWK maintainer(s)

I am using an Ubuntu 18.04.4 LTS distro running 
$ awk --version
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2016 Free Software Foundation.

For this distro this is the latest release of awk/gawk.

I am intending to use RS to separate records based on a /RE/ == ^---$.
Where I have managed to do this previously usually using the dual newline
capability by setting RS to a null string, using an actual RE seems to not
work (see below).  I do not believe the RE is incorrect since using grep for
example finds the strings correctly.

Please either tell me I have it wrong or that it is a known "feature".

For avoidance of doubt, the idea is that the record(s) are separated by a
line of 3 hyphens with NO whitespace and ended by a newline character.

EXAMPLE:
$ LC_ALL=C awk --posix 'BEGIN {RS="^---$";ORS="\n\n"}  {print $0,RS,NR}'
-
--
---
----
---
-
--
---
----
---
 ^---$ 1

$ 

Or, without the POSIX flag,
$ LC_ALL=C awk  'BEGIN {RS="^---$";ORS="\n\n"}  {print $0,RS,NR}'
-
--
---
----
---
-
--
---
----
---
 ^---$ 1

$
And using the set variable option,
$ LC_ALL=C awk -v RS="^---$" 'BEGIN {ORS="\n\n"}  {print $0,RS,NR}'
-
--
---
----
---
-
--
---
----
---
 ^---$ 1

$

As you see all 3 give similar/same results.

Regards
Phil

-- 
Phil J Fisher         address@hidden
Mobile:   +44 7984 781 929 (please leave message if busy or N/A)
Director, PeeJayEff Services Ltd
IT Consultancy and Technical Training in UNIXes/Linux
http://www.peejayeff.co.uk/

Email and any attachments sent are scanned by McAfee
Anti-Virus but integrity cannot be guaranteed.
_____________________________________________________





reply via email to

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