Can anyone explain why this does not work?
grep -ne '[A-Za-z]{1,30}\ [A-Z][a-z]{1,30}\W[A-Za-z]{1,30}\ [0-9]{1,30}\W[0-9]{5}\ [A-Za-z]{1,30}(\ [A-Za-z]{1,30})?' emails
Can anyone explain why this does not work?
grep -ne '[A-Za-z]{1,30}\ [A-Z][a-z]{1,30}\W[A-Za-z]{1,30}\ [0-9]{1,30}\W[0-9]{5}\ [A-Za-z]{1,30}(\ [A-Za-z]{1,30})?' emails
First, you are using extended regular expression (ERE) syntax like {}, () and ?. Add option -E to use ERE or do escape {} and () with backslashes and replace ? like this: grep -ne '[A-Za-z]\{1,30\} [A-Z][a-z]\{1,30\}\W[A-Za-z]\{1,30\} [0-9]\{1,30\}\W[0-9]\{5\} [A-Za-z]\{1,30\}\( [A-Za-z]\{1,30\}\)\{0,1\}' emails
Second, you are escaping spaces with backslashes inside single quotes. While most implementations of grep will handle this as simple spaces, the posix standard considers this undefined: The interpretation of an ordinary character preceded by a backslash ( '\' ) is undefined.
There may be additional problems, but we can't know without knowing the syntax of your file and what you want to grep