Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'^' matches newline at EOF #159

Open
pbsds opened this issue May 25, 2022 · 2 comments
Open

'^' matches newline at EOF #159

pbsds opened this issue May 25, 2022 · 2 comments
Labels
C-bug Category: Something isn't working

Comments

@pbsds
Copy link

pbsds commented May 25, 2022

The trailing newline is a posix standard, which the normal posix tools rightfully ignores. sd however seems not to.

pbsds@bjarte ~$ echo -e "1\n2\n3"  | sed -e 's/^/prefix-/'
prefix-1
prefix-2
prefix-3
pbsds@bjarte ~$ echo -e "1\n2\n3"  | sd '^' prefix-
prefix-1
prefix-2
prefix-3
prefix-

Version: sd 0.7.6

@xosxos
Copy link

xosxos commented Jul 21, 2022

The same goes for $. Also, it appears that sd cannot handle - as the first char of a string and it cannot be conveniently escaped either.

echo -e "1\n2\n3" | sd "$" "-suffix"

error: Found argument '-u' which wasn't expected, or isn't valid in this context

USAGE:
    sd <find> <replace-with> --string-mode

For more information try --help

Promising stuff with the benchmarks against sed, but it seems like the project is archived.

@pbsds
Copy link
Author

pbsds commented Jul 21, 2022

The - is kind of expected, although a bit unintuitive. The common way for unix cli tools to escape positional arguments that happen to start with a - is to stop parsing flags altogether after --. This is likely a GNU invention.

$ echo -e "1\n2\n3" | sd -- "$" "-suffix"
1-suffix
2-suffix
3-suffix
-suffix

@CosmicHorrorDev CosmicHorrorDev added the M-needs triage Meta: Maintainer label me! label May 17, 2023
@CosmicHorrorDev CosmicHorrorDev added C-bug Category: Something isn't working and removed M-needs triage Meta: Maintainer label me! labels Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants