使用sed将换行符转义符'\ n'替换为换行符转义符'\\ n' [英] Replacing newline escape '\n' with an escaped newline escape '\\n' using sed
本文介绍了使用sed将换行符转义符'\ n'替换为换行符转义符'\\ n'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 sed
用文字 \\ n
代替文字项 \ n
(不是换行符,文字)..我已经尝试过了:
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'
此有效",但我需要它输出文字字符 \\ n
.现在,我最终得到这样的东西:
This "works" but I need it to output the literal characters \\n
. Right now I end up with something like this:
"Refreshing \
\
\
state prior"
我是否可以在 sed
输出中维护 \\ n
?
Is there a way for me to maintain the \\n
in sed
output?
推荐答案
要获取 \\ n
,请在您的sed中再添加一个 \
:
To get \\n
add one more \
to your sed:
echo "Refreshing \n\n\n state prior" | sed 's/\\n/\\\\n/g'
您要使用 \\\ n
进行的操作是打印 \
字符,然后添加 \ n
,这会引起新的一行
What you were trying to do with \\\n
was to print \
character and then add \n
which caused a new line.
这篇关于使用sed将换行符转义符'\ n'替换为换行符转义符'\\ n'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文