嗨,我正在尝试使用sed将文本添加到文件的第一行。到目前为止,我已经尝试了:
#!/bin/bash
touch test
sed -i -e '1i/etc/example/live/example.com/fullchain.pem;\' test
这个不起作用,还尝试了
#!/bin/bash
touch test
sed -i "1i ssl_certificate /etc/example/live/example.com/fullchain.pem;" test
这似乎也不起作用了,但奇怪的是当我尝试使用
时#!/bin/bash
touch test
echo "ssl_certificate /etc/example/live/example.com/fullchain.pem;" > test
当我使用cat test
命令时,第一行文本会出现,但是一旦我键入sed -i "2i ssl_certificate_key /etc/example/live/example.com/privkey.pem;"
命令后,我看不到应该在第二行执行的信息,这是ssl_certificate_key /etc/example/live/example.com/privkey.pem;
所以我的问题总结如下:
- 可以使用sed将文本插入新创建文件的第一行吗?
- 如果可以,最佳的方法是在第一行文本之后插入文本?