替换所有出现的“."使用sed在'='之前加上'_' [英] Replace all Occurences of '.' with '_' before '=' using sed
问题描述
我有一个如下的属性文件:
I have a properties file as below:
build.number=153013
db.create.tablespace=0
db.create.user=0
db.create.schema=0
upgrade.install=1
new.install=0
configure.jboss=0
configure.jbosseap=false
configure.weblogic=1
configure.websphere=0
我需要将这些变量导入到Shell脚本中.如你所知, '.'不是在Linux中用作变量的有效字符.我将如何使用sed替换所有出现的."在'='和'_'之前.我已替换所有出现的."但是有些属性的值包含一个."我不想修改.
I need to import these variables into a shell script. As you know, '.' is not a valid character to use as a variable in linux. How would I use sed to replace all occurrences of '.' before the '=' with '_' . I have replaced all occurrences of '.' but there are some properties that have values which contain a '.' that I would like to not modify.
感谢您的帮助!
谢谢!
推荐答案
您可以使用
sed -e ':b; s/^\([^=]*\)*\./\1_/; tb;'
只要匹配成功,它就会将 stringWithoutEquals _
替换为 stringWithoutEquals _
.实际上,这会将所有.
之前的所有.
替换为 _
.
It replaces stringWithoutEquals.
with stringWithoutEquals_
for as long as the match succeeds. In effect, this replaces all the .
's before the =
with _
.
这篇关于替换所有出现的“."使用sed在'='之前加上'_'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!