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
\s+$
matches newline at the end of the file and newlines on empty lines
#291
Comments
While the end newline is the posix standard sd isn't posix compliant, and it's not a goal of the project afaik. You tell it to replace whitespaces and it does just that. |
Sure, matching the final newline makes sense. What is unexpected to me is that it seems to match them in some cases only: on empty lines, yes, on lines with non-whitespace characters, no, unless that line is the final line, then yes again. Is there some other logic that I'm overlooking? |
This is expected because sd doesn't work in a line-by-line mode, the answer lies in the regex. The regex means "at least one whitespace and a newline" |
Ah, indeed I didn't realize the pattern can span multiple lines. And then I guess |
Is there a way to enable line-by line mode? Normally, you would enable multiline mode with |
Currently no, but it's planned. |
From Example 2 in the quick guide ("let's trim some trailing whitespace"),
sd '\s+$' ''
seems to eat the newline at the end of the file, and newlines on empty lines, but not the newlines on the other lines.Example:
echo -en "test\n\ntest\n" | sd '\s+$' ''
results in"test\ntest"
. Just wondering if this is intended behavior? It strips the whitespace alright, but I did not expect it to touch those newlines.The equivalent
sed
command behaves as I expected:echo -en "test\n\ntest\n" | sed -E 's/\s+$//g'
leaves this input unchanged.The text was updated successfully, but these errors were encountered: