im trying to search for a WORD in a file which
begins with a number
followed by a hypen
follwed multiple words
and end with a dot "."
and pront the entire line which matches the above.
Please note that there is a space at the begining of each line
Such a consistent formulation of a question deems a longer answer: you won't need multiple search patterns, you will only need one - and because you have already exactly specified what you need it is quite simple. Let us try:
OK: Note that not every grep understands "-w" but since you already used it i suppose yours does:
grep -w
grep -w '[0-9][0-9]*'
grep -w '[0-9][0-9]*-'
It is not clear what you mean by "words" here because it is definitely not the same meaning as you used above. I take it (from your example) that you mean sequences of capitalized characters, digits or hyphens, yes? If so:
grep -w '[0-9][0-9]*-[A-Z0-9-]*'
We need to escape the dot, because it has a special meaning to grep ("any character"):
Nice approach. You might want to add a plus sign or a star to allow for multiple words. And, not sure if two or more adjacent minus signs are acceptable?
You are right, the missing asterisk was a typo, which i have corrected now. Thank you for spotting it.
You are right about adjacent hyphens maybe being not allowed, but that is a lack of information from the threads o/p. If he can better specify his needs i can construct better suited regexps. The point, though, was to show how a regexp can be constructed from a specification at all.