简体   繁体   English

Shell脚本-Unix

[英]Shell Script - Unix

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" 上面的命令在UNIX上可以正常工作,其中grep -v排除响应代码为“ 000”的记录

However, along with "000", I need to exclude the following response codes too: "404", "410", "403", "406" 但是,连同“ 000”一样,我也需要排除以下响应代码:“ 404”,“ 410”,“ 403”,“ 406”

I am new to unix shell script. 我是unix shell脚本的新手。

If anyone knows how to do it, please help. 如果有人知道该怎么做,请帮忙。 Appreciate your help. 感谢您的帮助。 Thanks. 谢谢。

you can do (foo|bar|blah) to implement OR in regex. 您可以执行(foo|bar|blah)在正则表达式中实现OR 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 http://www.regular-expressions.info/alternation.html

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 中间的(?:000|40[346]|410)非捕获组提供要排除的代码列表
  • | is the alternation (OR) operator 是交替(OR)运算符
  • [346] means one character that is either 3 , 4 or 6 [346]表示一个字符,该字符或者346

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM