sed

sed - combine two replace command into one line


I have below two line command to replace in files under current directory. I would like to combine it to one line command to improve performance.

find . -type f -name '*' | xargs sed -i 's/hello_release_demo/hello_demo/g'
find . -type f -name '*' | xargs sed -i 's/hello_debug_demo/hello_demo/g'

How should I use one sed command to handle two similar replace?


Solution

  • You can use an extended regular expression, with the -E option:

    sed -E -i 's/hello_(release|debug)_demo/hello_demo/g'