[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: replace problem with GNU sed 3.02.80
From: |
Hans-Bernhard Broeker |
Subject: |
Re: replace problem with GNU sed 3.02.80 |
Date: |
25 Apr 2002 14:11:30 GMT |
Lee Howard <address@hidden> wrote:
[...]
> bash-2.04$ export POSIXLY_CORRECT=1; echo "A" | sed '/A/s;;a;g'
> aAa
> bash-2.04$ export POSIXLY_CORRECT=1; echo "A" | sed 's/A/a/g'
> a
> bash-2.04$ unset POSIXLY_CORRECT; echo "A" | sed '/A/s;;a;g'
> a
> Is this behavior (A -> aAa) intentional?
I'm not quite sure. I would have expected 'aaa' or 'a', off-hand,
depending on whether an empty regexp is supposed to match a null
string or not. The symptoms you got mean that an empty regexp matches
exactly the empty string, but no non-empty string, in POSIXLY_CORRECT
mode. In normal mode, it matches exactly every non-empty string,
instead.
> I thought that the 's/A/a/g' syntax would be identical in behavior
> to '/A/s;;a;g'.
No, it quite definitely isn't. A leading /A/ means that the
replacement happens in any *line* that has an 'A' anywhere in it. The
'A' in 's;A;a;g' means that replacements happen only to the 'A'
itself.
--
Hans-Bernhard Broeker (address@hidden)
Even if all the snow were burnt, ashes would remain.