[英]Regular expression for replacing using sed
What could be the sed syntax to replace the text from a yaml(qa.yaml) file which contain below line.什么可能是 sed 语法来替换包含以下行的 yaml(qa.yaml) 文件中的文本。
image: "1xxxxxxxxxx.dkr.ecr.eu-west-2.amazonaws.com/abc-zyx-123/prod:a.b.c"
image2: "1xxxxxxxxxx.dkr.ecr.eu-west-2.amazonaws.com/abc-zyx-456/prod:1.2.3.4"
Now I what to replace the last version ie "1.2.3" and "2.3.4" from the yaml file during docker build.现在我要在 docker 构建期间从 yaml 文件中替换最后一个版本,即“1.2.3”和“2.3.4”。 I am taking parameter value from Jenkins.我从 Jenkins 获取参数值。 So lets say 1st parameter is image and second parameter is image2所以让我们说第一个参数是图像,第二个参数是图像2
I could have done but this abc could be change so what the best reg expression for this scenario?我本来可以做的,但是这个 abc 可能会改变,那么这种情况下最好的 reg 表达式是什么?
RUN sed -i -e "s@\a.b.c/$image" /qa.yaml
Thank you for helping感谢您的帮助
Use利用
sed -i "s@[^:][^:]*\$@$image" /qa.yaml
It will replace one or more characters other than a colon at the end of the string with the text in the image
variable that should not contain @
character.它将用image
变量中不应包含@
字符的文本替换字符串末尾除冒号以外的一个或多个字符。 If it is there, replace @
with #
, or ~
, or ,
, just make sure there is no such character in the image
.如果存在,请将@
替换为#
、或~
或,
,只要确保image
中没有这样的字符即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.