sed is printing a substituted line twice

2020-03-27 11:32发布

问题:

I am running the following command:

find /home/debajdas/checkout -name 'pom.xml' -or -name '*.properties' | xargs sed -i 's/10.0.0.0.3/10.0.0.0.4/gpw changes'

But it's replacing

<version>10.0.0.0.3</version>

with

<version>10.0.0.0.4</version>
<version>10.0.0.0.4</version>

Why is it getting replaced with 2 lines ?

回答1:

You must remove 'p' that prints current pattern space.

sed -i 's/10\.0\.0\.0\.3/10.0.0.0.4/gw changes'


回答2:

GNU sed

sed -i 's/\.3/.4/w changes'