【发布时间】:2020-05-10 19:12:56
【问题描述】:
尝试插入
主机:本地主机
端口:5432
用户名:postgres
密码:postgres
用 bash 脚本导入 database.yml 文件,我已经 终于取得了一些成功。到目前为止的脚本如下:
#!/bin/sed -f
/^development:/i\ \ host: localhost\n port: 5432\n username: postgres\n password: postgres
但它仍然在输入之前留下一个空行。如何在同一个 bash 文件中删除它?我现在需要做的最后一件事是让输出来自
Line
Line
host: localhost
port: 5432
username: postgres
到:
Line
Line
host: localhost
port: 5432
username: postgres
在上述同一个 bash 文件中使用搜索和匹配参数。
【问题讨论】:
-
您在shebang中指定了
#!/bin/sed -f,然后您调用了命令sed本身,而sed中不存在该命令(解释为命令s) -
您要输出更改,还是实际编辑文件?如果是后者,
ed在语法上会简单得多。 -
也就是说,根据行号将数据插入到 YAML 文件中是很脆弱的。
-
您应该寻找有关 insert multiple lines with sed 的问题,您会看到您的问题已经在很多类似这样的线程中得到解答:stackoverflow.com/questions/25270611/…
-
试试
sed '23s/^/host: localhost\n port: 5432\n username: postgres\n password: postgres\n/' database.yml