Unix grep regex how to grep for
I have a text file
$ cat test.log
SYB-01001
SYB-18913
SYB-02445
SYB-21356
I want to grep for 01开发者_运维技巧001 and 18913 only whats the way to do this
I want the output to be
SYB-01001
SYB-18913
SYB-02445
I tried this but not sure whats wrong with it
grep 'SYB-(18913)|0*)' test.log
Use the -E
flag for "extended regular expressions" with grep.
e.g.
grep -E 'SYB-(0|18913)' test.log
Other things to be aware of:
- parentheses must match (for every opening bracket you want a closing bracket)
0*
means zero or more0
characters - in truth this will match everything
Try that :
grep 'SYB-\(18913\|0*\)' test.log
But you maybe don't want the 0*
part to act like this. Maybe 0+
is better.
awk
awk '/SYB-(0|18913)/' file
Your brackets are out. Try
grep 'SYB-[18913|0*]' test.log
精彩评论