Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading