0
grep "<ValidateXYZResponse" filename.log* | grep -v "<ResponseCode>000<ResponseCode>"

Above command works fine in UNIX where grep -v excludes the records having response code "000"

However, along with "000", I need to exclude the following response codes too: "404", "410", "403", "406"

I am new to unix shell script.

If anyone knows how to do it, please help. Appreciate your help. Thanks.

4
  • Read some basic documentation on regex. There is something called alternation. Commented Jul 1, 2014 at 9:57
  • This question appears to be off-topic because it is about unwillingness to RTFM. Commented Jul 1, 2014 at 9:58
  • @devnull - I sure will learn the basics. Asked question here because I have to send some reports quickly and this is the first time I am using unix shell script. Commented Jul 1, 2014 at 10:06
  • It would have taken you much less than the time in which you received the first answer only if you were willing to RTFM. Good luck! Commented Jul 1, 2014 at 10:08

2 Answers 2

3

you can do (foo|bar|blah) to implement OR in regex. Like:

grep ...|grep -v '<...>\(000\|40[346]\|410\)<...>'

or

grep ...|grep -vE '<...>(000|40[346]|410)<...>'

detailed explanation about regex-alternation:

http://www.regular-expressions.info/alternation.html

Sign up to request clarification or add additional context in comments.

Comments

1
grep "<ValidateXYZResponse" filename.log* | grep -Pv "<ResponseCode>(?:000|40[346]|410)<ResponseCode>"
  • The (?:000|40[346]|410) non-capturing group in the middle gives a list of codes to exclude
  • | is the alternation (OR) operator
  • [346] means one character that is either 3, 4 or 6

1 Comment

grep -P (for perl regexen?) is a GNUism unsupported by many grep implementations. grep -E is more portable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.