I want to grep a HTTP access log, but I'm not able to write an efficient regular expression. Here is what I use now:
grep \/console access.log | grep -v .gif | grep -v .js |grep -v .c开发者_C百科ss
How can I shorten it? Thanks!
grep does not support lookahead, so you'll still have to have two instances:
grep /console access.log | grep -v '\.\(gif|js|css\)'
With negative lookahead, a smaller, although not necessarily more readable regexp would be
^(?!.*?\.(gif|js|css)).*/console.*$
This may or may not feel simpler.
sed -r -n -e '/\.(js|css|gif)/d' -e '\%/console%p' access.log
精彩评论