Search code examples
regexsed

sed command OR operator not working in a group


I'm running on MacOS. I have a file which contains these lines:

This is ('apple').
This is ('orange').
This is ('banana').

When I search for an apple using sed it works:

cat file.txt | sed -n "/(\('apple'\)/p"

But when I try to search for an apple or an orange, it does not work and returns nothing:

cat file.txt | sed -n "/(\('apple'|'orange'\)/p"

What should be the correct sed regex to use or operator inside a group capture??

Thank you.


Solution

  • I finally make it work by adding the -E flag.

    cat file.txt | sed -nE "/\('(apple|orange)/p"