Regex – Use sed to replace all occurrences of ‘=’ with ‘_’ before ‘.’

Use sed to replace all occurrences of ‘=’ with ‘_’ before ‘.’… here is a solution to the problem.

Use sed to replace all occurrences of ‘=’ with ‘_’ before ‘.’

I have a properties file as follows:

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

I need to import these variables into a shell script. As you know, ‘. ‘ is not a valid character used as a variable in Linux. How I will use sed to replace all occurrences”. “Before ‘=’ and ‘_’. I’ve replaced all that appeared”. However, some properties contain “.” I don’t want to modify.

Thanks for any help!

Thanks!

Solution

You can use

it

sed -e ':b; s/^\([^=]*\)*\./\1_/; tb; '

As long as the match is successful, it replaces stringWithoutEquals. with stringWithoutEquals_. In effect, this replaces all the . before = with _

Related Problems and Solutions