GNU bug report logs -
#47281
sed: problem with hex replace a literal '$'
Previous Next
To reply to this bug, email your comments to 47281 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-sed <at> gnu.org
:
bug#47281
; Package
sed
.
(Sat, 20 Mar 2021 13:51:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Bastian Bittorf <bb <at> npl.de>
:
New bug report received and forwarded. Copy sent to
bug-sed <at> gnu.org
.
(Sat, 20 Mar 2021 13:51:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Dear hard working developers,
when replacing in hex mode, and a '$' = \x24 is at
the end of the search string, it seems to be parsed
as 'end', which was at least not intended by my usage:
e.g.
# echo 'foo $bar$ baz' >testfile
# hexdump -C testfile
00000000 66 6f 6f 20 24 62 61 72 24 20 62 61 7a 0a |foo $bar$ baz.|
# ^^^^^^^^^^^^^^^
# i want to replace '$bar$'
# sed 's/\x24\x62\x61\x72\x24/\x65\x65\x65\x65\x65/' testfile
foo $bar$ baz
(no match/replacement happens)
# now omit the last char '$'
# sed 's/\x24\x62\x61\x72/\x61\x65\x65\x65/' testfile
foo aeee$ baz
# now making the match on char longer:
# sed 's/\x24\x62\x61\x72\x24\x20/\x61\x65\x65\x65\x65\x20/' testfile
foo aeeee baz
# this happends with latest trunk/master:
# bastian <at> ryzen:~/software/sed$ sed/sed --version
sed/sed (GNU sed) 4.8.7-b352-dirty
I stumpled over this behaviour while
replacing real binary data, where randomly
a 0x24 was involved at the end of the match string
Thanks for reading and maybe fixing 8-)
bye, bastian
Information forwarded
to
bug-sed <at> gnu.org
:
bug#47281
; Package
sed
.
(Sat, 20 Mar 2021 17:07:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 47281 <at> debbugs.gnu.org (full text, mbox):
Hello,
the behavior you are describing is documented here:
https://www.gnu.org/software/sed/manual/sed.html#Escaping-Precedence
If you want to produce a basic regular expression given a string to be matched literally, precede any of $*.[\]^ with \
Likewise, if you are using hex escapes (\xHH), precede any of \x24 \x2a \x2e \x5b \x5c \x5d \x5e with \x5c
Information forwarded
to
bug-sed <at> gnu.org
:
bug#47281
; Package
sed
.
(Sun, 21 Mar 2021 16:06:02 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
> Hello,
>
> the behavior you are describing is documented here:
> https://www.gnu.org/software/sed/manual/sed.html#Escaping-Precedence
>
> If you want to produce a basic regular
> expression given a string to be matched
> literally, precede any of $*.[\]^ with \
> Likewise, if you are using hex escapes (\xHH),
> precede any of \x24 \x2a \x2e \x5b \x5c \x5d \x5e with \x5c
Hi Nora,
thanks for your help suggesting the escaping.
I understand, that this behaviour is valid and not a bug.
Maybe you can post this to the Mailingslist as well,
i'am not subscribed there.
Indeed this is really awkward, but I have to
accept that and use now something like that:
#!/bin/sh
#
# [...]
#
# case "$hex" in
# 24|2a|2e|5b|5c|5d|5e)
# hex="5c\x$hex"
# ;;
# esac
see:
https://github.com/bittorf/kritis-linux/commit/d3cc6c84a6c021ae2f7e9351f9f4ef0fc7098c0b
Thanks again & bye,
Bastian Bittorf
This bug report was last modified 3 years and 230 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.