Replacing newline escape '\n' with an escaped newline escape '\\n' using sed
问题 I am trying to replace the literal term \n (not a newline, the literal) by the literal \\n using sed . I've tried this: echo '"Refreshing \n\n\n state prior"' | sed 's/\\n/\\\n/g' This "works" but I need it to output the literal characters \\n . Right now I end up with something like this: "Refreshing \ \ \ state prior" Is there a way for me to maintain the \\n in sed output? 回答1: To get \\n add one more \ to your sed: echo "Refreshing \n\n\n state prior" | sed 's/\\n/\\\\n/g' What you were