I looked at a very similar question but was unable to resolve the issue Replace comma with newline in sed
I am trying to convert :
characters in a strin
You do not need echo -e
because you have \n
in sed
, not in echo
statement.
So, the following should work (note that I have changed '\n'
to \n
):
echo -e 'this:is:a:test' | sed "s/\:/\n/g"
or
echo 'this:is:a:test' | sed "s/\:/\n/g"
Also note that you do not need to escape :
so the following will work too (thanks to @anishsane)
echo 'this:is:a:test' | sed "s/:/\n/g"
Below is just to reiterate why you need -e
for echo
$ echo -e "hello \n"
hello
$ echo "hello \n"
hello \n