Reputation: 185
I'm new with regexp and I believe this is a beginner's glitch in getting the output.
My regexp for AB(CD) digits/digits is: [A-Z]+[^a-zA-Z0-9][A-Z]+[^a-zA-Z0-9] [0-9]+[^a-zA-Z0-9][0-9]+
Grep command is: grep "regexp" xyz.txt
there's no output to above command, but when I use sublime editor for same regex, i gets the desired result. Tried many attempts with grep command , the only time it gave results is when I deleted the [0-9]+[^a-zA-Z0-9][0-9]+
portion from regex because there is a space in between but still the results were not desired. Tried grep -e
and grep --regexp=
too, no results.
Can someone tell me where I went wrong or the correct syntax for this command. Much grateful.
Edit:
The data looks like the following:
AB(C.D.) nnnnn/nnnnnn
A.B(C.D.) nnnnnn/nnnnn
A.B.(CD) nnnnn/nnnnnn
AB(CD) nnnnn/nnnnnn
AAB(CD) nnnnn/nnnnnn
....
....
further P & C
I was looking only for AB(CD) nnnn/nnnnnn. Would really like to learn the correct expression.
Upvotes: 0
Views: 148
Reputation: 36
Use grep -E as it switches grep into a special mode so that the expression is evaluated as an ERE (Extended Regular Expression) as opposed to its normal pattern matching.
Upvotes: 2