By default grep
patterns don't accept standard "extended" regular expression syntax (thanks to tripleee for pointing out how wrong my first writing of that was), so your syntax doesn't get translated as you expect. You can enable the extended patterns with egrep
or -E
:
grep -E '^ac{1,2}' place/file/input.txt > place/file/output.txt
-E
Match using extended regular expressions. Treat each pattern specified as an ERE, as described in the Base Definitions volume of IEEE Std 1003.1-2001, Section 9.4, Extended Regular Expressions. If any entire ERE pattern matches some part of an input line excluding the terminating , the line shall be matched. A null ERE shall match every line.
from the POSIX docs
though, 3 c's is also at 1 or 2 followed by anything else, so you'd want to make sure the next character is not a c:
grep -E '^ac{1,2}[^c]' place/file/input.txt > place/file/output.txt
Additionally, as James Brown points out, you can escape many of the characters to make grep
process the regex as desired without the -E
.