brain storm
brain storm

Reputation: 31252

what does -itmp flag on sed command do?

I came across the following in our legacy bash code

sed -itmp <something> file.txt

Since I did not understand what it does clearly, I tried the following

Here is the content of file.txt before running sed

dummy={my.java.home}
dummy={my_java_home}

I run now

sed -itmp "s#{my.java.home}#${JAVA_HOME}#g" file.txt

After I run this, I get the following

dummy=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
dummy=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

I can see how sed replaces. But I fail to understand sed replaces both my_java_home and my.java.home in my original file although I asked it to change only my.java.home when issuing sed command above.

Thanks

Upvotes: 0

Views: 71

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174736

Because dot in your regex matches any charcter not only the literal dot. So i suggest you to escape the dots present in your regex , so that it matches my.java.home string only.

sed -itmp "s#{my\.java\.home}#${JAVA_HOME}#g" file.txt

And you won't actually need a tmp parameters.

sed -i "s#{my\.java\.home}#${JAVA_HOME}#g" file.txt

Upvotes: 1

Related Questions