Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean OR in sed regex

I'm trying to replace all references of a package named boots in a configuration file.

The line format is add fast (package OR pkg) boots-(any-other-text), e.g.:

add fast package boots-2.3
add fast pkg boots-4.5

I want to replace it with:

add yinst pkg boots-5.0

I've tried the following sed commands:

sed -e 's/add fast (pkg\|package) boots-.*/add yinst pkg boots-5.0/g'
sed -e 's/add fast [pkg\|package] boots-.*/add yinst pkg boots-5.0/g'

What's the right regex? I think I'm missing something in the boolean or (package or pkg) part.

like image 458
Adam Matan Avatar asked Aug 31 '25 14:08

Adam Matan


1 Answers

sed -e 's/add fast \(pkg\|package\) boots-.*/add yinst pkg boots-5.0/g'

You could always avoid the OR by doing it twice

sed 's/add fast pkg boots-.*/add yinst pkg boots-5.0/g
s/add fast package boots-.*/add yinst pkg boots-5.0/g'
like image 153
bobbogo Avatar answered Sep 13 '25 08:09

bobbogo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!