如何使用换行符将 sed 的结果存储在变量中
我尝试以这种方式存储 sed 的数据,
line=$(sed 's/old/new/g' data.t)
但问题是换行符没有存储在变量中。 sed 命令产生一个输出,其中有新行,而我想存储它们时,变量不存储新行。 我怎样才能在变量中存储换行符?
i tries storing data of sed in this way,
line=$(sed 's/old/new/g' data.t)
but the problem is newline do not get stored in a variable.
the sed command produces a output in which there are new lines the variable doesnt stores the new lines while i want to store them.
How can i store newline in the variable too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
换行符就在那里,您只需正确引用变量即可看到它。
echo
不是一个很好的检查变量的命令,但这应该像你想要的那样工作:The newline is there, you just need to quote the variable properly to see it.
echo
is not a very good command for inspecting your variables,but this should work like you want:它确实保留了换行符,但是要在使用它时看到它们,您需要双引号它
It does keep the newlines, but to see them when you use it, you need to double quote it
试试这个
我不确定你的 sed cmd,'a/old/new/s'。我本来希望看到类似“s/old/new/g”的内容,但祝你好运。
我希望这有帮助。
Try this
I'm not sure about your sed cmd, 'a/old/new/s'. I would have expected to see something like 's/old/new/g', but good luck.
I hope this helps.