diff --git a/grep.1 b/grep.1 index 6402dec..16cd825 100644 --- a/grep.1 +++ b/grep.1 @@ -3,7 +3,7 @@ grep \- search files for a pattern .SH SYNOPSIS .B grep -.RB [ \-cilnqv ] +.RB [ \-Ecilnqv ] .I pattern .RI [ file ...] .SH DESCRIPTION @@ -17,6 +17,9 @@ The status code is 0 if any lines match, and 1 if not. If an error occurred the status code is 2. .SH OPTIONS .TP +.B \-E +matches using extended regex. +.TP .B \-c prints only a count of matching lines. .TP diff --git a/grep.c b/grep.c index 541c048..7217539 100644 --- a/grep.c +++ b/grep.c @@ -8,6 +8,7 @@ static void grep(FILE *, const char *, regex_t *); +static bool Eflag = false; static bool iflag = false; static bool vflag = false; static bool many; @@ -22,8 +23,11 @@ main(int argc, char *argv[]) regex_t preg; FILE *fp; - while((c = getopt(argc, argv, "cilnqv")) != -1) + while((c = getopt(argc, argv, "Ecilnqv")) != -1) switch(c) { + case 'E': + Eflag = true; + break; case 'c': case 'l': case 'n': @@ -43,6 +47,8 @@ main(int argc, char *argv[]) fprintf(stderr, "usage: %s [-cilnqv] pattern [files...]\n", argv[0]); exit(2); } + if(Eflag) + flags |= REG_EXTENDED; if(iflag) flags |= REG_ICASE; regcomp(&preg, argv[optind++], flags);