sed 替换行尾
我正在尝试在行尾添加一堆 0。该行的识别方式是它后面跟着一行以“expr1”开头的行,
在 Vim 中我所做的是:
s/\nexpr1/ 0 0 0 0 0 0\rexpr1/
并且它工作正常。我知道在 ubuntu 中 \n 通常用于终止该行,但每当我这样做时,我都会得到一个 ^@ 符号,所以 \r 对我来说效果很好。我以为我可以将它与 sed 一起使用,但它并没有真正起作用。这是我通常写的:
sed "s/\nexpr1/ 0 0 0 0 0 0\rexpr1/" infile > outfile
I'm trying to add a bunch of 0s at the end of a line. The way the line is identified is that it is followed by a line which starts with "expr1"
in Vim what I do is:
s/\nexpr1/ 0 0 0 0 0 0\rexpr1/
and it works fine. I know that in ubuntu \n is what is normally used to terminate the line but whenever I do that I get a ^@ symbol so \r works fine for me. I thought I'd use this with sed but it hasn't really worked. here is what I normally write:
sed "s/\nexpr1/ 0 0 0 0 0 0\rexpr1/" infile > outfile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
行尾标记是 $。试试这个:
根据您的环境,您可能需要转义 $。
The end-of-line marker is $. Try this:
Depending on your environment, you might need to escape the $.