Linux – automatic replace a string with a new one in multiple files

I did have to do a lots of modification in almost 600 files, and i did it using Linux SED:
grep -ilr ‘UA-1234567-1’ * | xargs -i@ sed -i ‘s/UA-1234567-1/UA-9876543-2/g’ @
what it really does is replace the string UA-1234567-1 with UA-9876543-2


  1. Your use of xargs is dangerous. To see why read:
    $ echo UA-1234567-1 > “foo’bar'”
    $ grep -ilr ‘UA-1234567-1’ * | xargs -i@ sed -i ‘s/UA-1234567-1/UA-9876543-2/g’ @
    $ cat “foo’bar'”
    Consider using GNU Parallel instead.
    $ grep -ilr ‘UA-1234567-1’ * | parallel sed -i ‘s/UA-1234567-1/UA-9876543-2/g’
    Watch the intro video to GNU Parallel at

  2. Tnx for the info i did not know that for some Unix there are problms with xargs as long as the lines do not contain ‘, ” or space.

Leave a comment

Your email address will not be published.