Grep and Regular Expressions Flashcards
What does grep do
Prints lines that match defined pattern
How do you use grep to search case insensative
grep -i “search pattern”
Shows lines not containing pattern
grep -v
Search for pattern in filename
grep error /var/log/messages
Search for lines starting with error
grep “^error” /var/log/messages
Search for lines ending with error
grep “error$” /var/log/messages
Search for all characters except (aeiou)
grep “[^aeiou]” /var/log/messages
Search for the pattern error and Error
grep [eE]rror /var/log/messages
Search for empty lines
grep “^$” /var/log/messages
Search for only un-commented lines
grep -v ^# /etc/ssh/sshd_config
What is egrep
same as grep but using extended regular expressions
What is fgrep
interprets patterns as list of fixed strings