grep Flashcards
grep
displays lines in a file or stream that match a pattern expressed as a regular expression
grep command syntax
grep options ‘regular expression’ file(s)
-i
ignores case for matching
-v
Doesn’t display lines matching expression
-n
Displays line and n lines after matching lines (linux)
-c
Displays count of number of occurrences
-l
Displays list of filenames only
-e exp
Specifies given expression and can use multiple times
-x
Matches pattern with entire line (doesn’t match embedded patterns)
-f file
Takes pattern from file, one per line
-E or egrep
Treats pattern as an extended regular expression (ERE)
-F
Matches multiple fixed strings (in fgrep-style)
-A n
Display line and n lines after matching lines (linux)
-B n
Display line and n lines before matching line (linux)
matches a pattern at the beginning of a line
The caret has a triple role to play in regular expressions. When placed at the beginning of a character class (e.g., [^a-z]), it _____ every character of the class. When placed outside it, and at the beginning of the expression (e.g., ^2…), the pattern is matched at the ____ of the line. At any other location (e.g., a^b), it matches ____ literally.
The caret has a triple role to play in regular expressions. When placed at the beginning of a character class (e.g., [^a-z]), it negates every character of the class. When placed outside it, and at the beginning of the expression (e.g., ^2…), the pattern is matched at the beginning of the line. At any other location (e.g., a^b), it matches itself literally.
grep special character (for making Basic Regular Expressions)
The end of a line
$
*
zero or more occurrences of the previous character
grep special character
(for making Basic Regular Expressions)
a single character that is one of the ones listed in
[ ]
a single character that is one of the ones listed in
[ … ].
(similar to [ … ] for shell
file matching)
.
Matches single character
[abc]
a single character a, b, c
[c1-c2]
A single character with the ASCII range represented by c1 and c2