-1

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?

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
YulkyTulky
  • 618
  • 4
  • 16

1 Answers1

1

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
Walter A
  • 17,923
  • 2
  • 22
  • 40