Reputation: 1980
How can I replace ;
with ;\n
(semicolon followed by a newline) in sed?
I've tried building off of
sed s/;/\\n/g file
and
sed -e '/;/G' file
but I can't get either to work
Upvotes: 4
Views: 980
Reputation: 61449
You need to cheat a bit: in bash
you can say
sed $'s/;/;\\\n/g'
or, portably (POSIX):
sed "s/;/;$(printf '\\\n')/g"
sed
does not portably/reliably handle backslash-escapes anywhere but in the pattern, and even there it's limited (POSIX only requires that \n
be handled, not \t
or the others). Note that you also need a backslash before the \n
so sed
doesn't read it as the end of the command.
Upvotes: 4
Reputation: 26574
sed -ie 's/;/;\n/g' <file>
That's assuming you want to do it inline in the file, remove the "i
" and just use "-e
" if that's not the case.
Upvotes: 1