You're viewing a comment by Human and its responses.

Human Permalink
June 25, 2012, 08:30

Thankyou. It worked like a charm.
I have been trying more on the lines of

sed -e '/AAA|BBB/!d;/CCC/!d'

but couldnt get it work. My reasoning says the above command should work (I assume I could use a regex as AAA|BBB in my first search). Am I missing something here?

Comment Responses

June 27, 2012, 19:27

Your reasoning is correct, and your program is actually correct.

The only problem is with the type of regular expressions sed uses. It uses so called "basic" regexes where | is an ordinary character.

You've to escape it to make it work like an alternation operator:

sed -e '/AAA\|BBB/!d;/CCC/!d'

Try this and it will work.

Also check out the -r argument to sed. It enables extended regular expressions, and your program will work:

sed -re '/AAA|BBB/!d;/CCC/!d'
Human Permalink
July 25, 2012, 09:09

Thankyou Peter. Both your suggestions worked.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "linux_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.