我在开头有一行空格,例如“Hello world”。 我想将此行插入文件中的特定行。 例如 在下一个文件中插入“hello world”
hello
world
结果:
hello
hello world
world
我正在使用这个 sed 脚本:
sed -i "${line} i ${text}" $file
问题是我的新行没有空格:
hello
hello world
world
最佳答案
可以对空格
字符进行转义,例如添加2个空格:
sed -i "${line} i \ \ ${text}" $file
或者您可以在 text
变量的定义中执行此操作:
text="\ \ hello world"
关于linux - sed 将带空格的行插入特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18439528/