shx icon indicating copy to clipboard operation
shx copied to clipboard

[sed] did not replace correctly

Open sntran opened this issue 1 year ago • 2 comments

With the following test.file:

[&_*]:foobar
"[&_*]:foobar"

With actual sed on macOS:

$ sed 's/\[\([^\&]*\)\&/\[\1\&/g' test.file
[&_*]:foobar
"[&_*]:foobar"

With shx sed:

npx shx sed 's/\[\([^\&]*\)\&/\[\1\&/g' test.txt                             
[&_*]:foobar
"[&_*]:foobar"

Node version: v20.12.2

sntran avatar Aug 01 '24 22:08 sntran

After reading shelljs doc on sed, the replacement must be a JS replacement string, i.e. shx sed 's/\[([^\&]*)\&/[$1&/g'.

So in term of being a wrapper around shelljs, this is not a bug in shx.

However, being a shell replacement for sed, it is a surprised, as I would expect the same syntax as sed.

Also, in sed, open and close parentheses need to be escaped I believe, but not with shx.

sntran avatar Aug 01 '24 22:08 sntran

Thanks for the report. Getting shx sed to be 100% compatible has been a challenge. I'd be willing to accept a contribution to the shx project if you're interested in working on this.

How does the current behavior compare to sed -e ... (extended regex syntax)?

nfischer avatar Oct 18 '24 06:10 nfischer