shell sed命令在给定文件的行尾等待

eeq64g8w  于 2023-06-24  发布在  Shell
关注(0)|答案(3)|浏览(99)

我正在尝试替换ini文件中两个部分之间的字符串。我正在使用sed命令,我能够实现我想要的,但在执行sed命令后,它将替换文本并等待控制台中文件末尾的输入。
我的ini文件是

[platform]
security=http://security:8080/
referral=http://mindapp:8000/
catalog=http://catalog:8080/
workorder=http://workorder:8080/
assets=http://assets:8080/
provider=http://provider:8080/

[app]
name=express
ssl=false
port=8080
hostname=0.0.0.0

在上面的文件中,我试图使用下面的命令在:8080之前添加namespace.cluster.svc.local。

sed -n -e '/\[platform\]/,/\[app\]/p' | sed -e '1d;$d' | sed 's/:/\.das-ci.svc.cluster.local&/2g' secrets.ini

有什么方法可以避免在执行命令后等待吗?

uqzxnwby

uqzxnwby1#

第一个命令等待stdin,执行以下操作

sed -n -e '/\[platform\]/,/\[app\]/p'  secrets.ini  | sed -e '1d;$d' | sed 's/:/\.das-ci.svc.cluster.local&/2g'

不过,您应该只调用sed一次。

gzszwxb4

gzszwxb42#

使用sed

sed -n '/\[platform]/,/\[app]/{//!s/:/.das-ci.svc.cluster.local&/2p}' input_file
security=http://security.das-ci.svc.cluster.local:8080/
referral=http://mindapp.das-ci.svc.cluster.local:8000/
catalog=http://catalog.das-ci.svc.cluster.local:8080/
workorder=http://workorder.das-ci.svc.cluster.local:8080/
assets=http://assets.das-ci.svc.cluster.local:8080/
provider=http://provider.das-ci.svc.cluster.local:8080/
bbmckpt7

bbmckpt73#

下面的命令工作正常。

sed -e '/\[platform\]/,/^$/s/:/\.das-ci.svc.cluster.local&/2g' secrets.ini

谢谢你@f-hauri-give-up-github

相关问题