103.7 Search text files using regular expressions Flashcards
What command do you usually use with regular expressions?
grep
What does a dot (.) represent in a regex?
A dot represents a single character. More than one dot can be used consecutively to represent more unknown characters in a row.
What symbol do you use to search for a string at the beginning of a line and at the end of a line in a regex?
At the beginning: ^
At the end: $
What syntax would you use to search for a line that contains a specified character using a regex?
grep [x]
What syntax would you use to search for a line that contains a string at the end using a regex?
grep bash$
What syntax would you use to search for a line that contains a string the beginning using a regex?
grep ^rpc
What syntax would you use to search for a line that contains either a capital or a lowercase character using a regex?
#grep -i [x] #grep [Xx]
What syntax would you use to search for a line in a file that begins with either a capital or lowercase A, then followed by any character and the third character being either a capital or lowercase A?
#grep ^[Aa] .[Aa] $grep -i ^[a].[a]
What symbols do you use to exclude a character from a search in a regex?
[^abc]
What does the star sign mean in a regex?
It matches zero or more of the preceding characters or expression.
What does the #egrep command do?
It searches a specified file line by line returning lines that contain a pattern matching a given regular expression.
What is the equivalent of egrep?
grep -E
How do you egrep a file for lines that contain {bash} at the end of the lines?
egrep ‘bash$’
How do you egrep a file just to know how many lines contain the string at the end of the lines?
egrep -c ‘bash$’
How do you egrep a file to find lines that contain a string at the beginning or another string at the end of the lines?
egrep ‘^rpc|nologin$’