sd
sd copied to clipboard
How to replace spaces with linebreaks?
Which syntax should I use to go from
First word. Another word.
to
First word.
Another word.
sd -s ". " '.\\n' text.txt
produces
First word.\n Another word.
with the space intact and no linebreak, just \n
.
Seems like using -s
option makes the replacement string to be literal string as well. You can either use a literal newline or use shell constructs like $''
quoting in bash
shell (see https://mywiki.wooledge.org/Quotes for details)
# without -s option
$ echo 'First word. Another word.' | sd '\. ' '.\n'
First word.
Another word.
# with -s option and bash $'' quoting
$ echo 'First word. Another word.' | sd -s '. ' $'.\n'
First word.
Another word.
# -s option and literal newline (press Enter key after .)
$ echo 'First word. Another word.' | sd -s '. ' '.
'
First word.
Another word.
I think the issue has to be closed, it is something related to bash and the understanding of -s
option
I've tweaked the documentation on --string-mode
to hopefully make it more clear that both the FIND
and REPLACE
args are treated as literal strings