sd icon indicating copy to clipboard operation
sd copied to clipboard

`\s+$` matches newline at the end of the file and newlines on empty lines

Open kbvw opened this issue 1 year ago • 6 comments

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.

kbvw avatar Feb 14 '24 16:02 kbvw