tags:

views:

53

answers:

4

Hi

I have a text file

$ cat test.log
SYB-01001
SYB-18913
SYB-02445
SYB-21356

I want to grep for 01001 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
+4  A: 

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 more 0 characters - in truth this will match everything
PP
Simply Brilliant thanks for -E trick
Lisa
A: 

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.

Colin Hebert
A: 

Your brackets are out. Try

grep 'SYB-[18913|0*]' test.log
Kevin McKelvin
Are you sure this is correct?
ghostdog74
Checked it on Linux Mint, gets the same output as the question was expecting.
Kevin McKelvin
`echo "SYB-11111" | grep 'SYB-[18913|0*]'`
ar
Definitely works here
Kevin McKelvin
A: 

awk

awk '/SYB-(0|18913)/' file
ghostdog74