如何使用 sed 将空行替换为文本?我尝试了之前发布的一些技巧,但没有用。有人可以帮我解决这个问题吗?
示例文件内容-
Linux is an os.
Linux is opensource
Linux has various flavors like fedora,centos etc.
我想用 hello 之类的文本替换这些空行。
最佳答案
如果您只想完全空行,只需匹配开始行然后结束行
sed -e 's/^$/Hello/g'
如果你还想匹配包含空格的行
sed -e 's/^ *$/Hello/g'
编辑:如果你想匹配所有只包含空格的行,一个更好的变体:
sed -e 's/^\s*$/Hello/g'
关于linux - 如何使用sed用文本替换空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24980072/