GNU bug report logs - #47281
sed: problem with hex replace a literal '$'

Previous Next

Package: sed;

Reported by: Bastian Bittorf <bb <at> npl.de>

Date: Sat, 20 Mar 2021 13:51:01 UTC

Severity: normal

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bastian Bittorf <bb <at> npl.de>
To: bug-sed <at> gnu.org
Subject: sed: problem with hex replace a literal '$'
Date: Sat, 20 Mar 2021 09:56:43 +0000
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




This bug report was last modified 4 years and 86 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.