SED:匹配包含换行符的字符串 [英] sed: match a string that contains a newline
本文介绍了SED:匹配包含换行符的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个字符串:
#
pap
基本上转化为一个 \\ T#\\ n \\ TPAP
,我想用来替换:
#
pap
python
这相当于 \\ T#\\ n \\ TPAP \\ n \\ tpython
。
在很多方面试图与 SED
,但它没有可能工作,因为 SED
采用了新的生产线不同的方式。我试着用:
Tried this with sed
in a lot of ways but it's not working maybe because sed
uses new lines in a different way. I tried with:
sed -i "s/\t#\n\tpap/\t#\tpython\n\tpap/" /etc/freeradius/sites-available/default
...并没有结果许多不同的其他方式。任何想法,我该怎么办我在这种情况下更换?
...and many different other ways with no result. Any idea how can I do my replace in this situation?
P.S。 Ubuntu的/ bash的
P.S. Ubuntu/bash
推荐答案
试试这符合GAWK:
awk -v RS="\0" -v ORS="" '{gsub(/\t#\n\tpap/,"yourNEwString")}7' file
如果你想要让 SED
处理新行,你必须先读取整个文件:
if you want to let sed
handle new lines, you have to read the whole file first:
sed ':a;N;$!ba;s/\t#\n\tpap/NewString/g' file
这篇关于SED:匹配包含换行符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文