I have a file like this:
This
file
has
newlines
and
tabs
and I want to generate something that looks like this:
This\n\tfile\nhas\nnewlines\nand\n\ttabs
How can I easily get this output?
I have a file like this:
This
file
has
newlines
and
tabs
and I want to generate something that looks like this:
This\n\tfile\nhas\nnewlines\nand\n\ttabs
How can I easily get this output?
I just added an answer to Replace newlines with literal \n that works here too.
Using the "new" -z
option you can do
sed -z 's/\t/\\t/g;s/\n/\\n/g' file
or
sed -z "s/\t/\\\t/g;s/\n/\\\n/g" file