Searching with grep
fgrep
Search file(s) for lines that match a fixed string. A variant of the grep command that does not allow the use of regular expressions. normally the default grep used
man 7 regex
pulls a specific manual - posix.2 expressions - explains how regex works
Regex Wildcard: -
range like 1-9
Regex Wildcard: .
represents any single character - will find any one letter or number
grep -r
searches all files in a directory and outputs filenames and lines containing matched results
Regex Wildcard: ()
slices up data that we're looking for like if looking for parts of a command or doing a sub-expression. can do a regex inside of a regex basically, nesting.
Regex Wildcard: $
the end of line or the end of a file name. opposite of ^
cat kermit.text | grep -E "[Kk]ermit"
this would search for the word kermit and would pull both upper and lower case entries
egrep
A variant of the grep command, used to search files for patterns using extended regular expressions.
what are regular expressions and why do they matter
grep relies on regular expressions (regex) and they rely on each other. grep is a search tool and regex are sets of criteria that grep uses. regex is a collection of wild cards that are supported by lots of software
cat cal-2019.txt | grep -E "^1[0-2]"
This would search for any number starting with a 1 but also has numbers following it as defined in the range. the quotations are just for wrapping the expression - they are not wildcards themselves
POSIX
a set of standards that an OS has to conform to if they want to call themselves a UNIX compatible OS. most distros are not POSIX compliant but some of them strive to be and come quite close
Regex Wildcard: \
escape character - used for when trying to use a true character and not trying to implement a regex function
Regex Wildcard: ^
find something at the beginning like where the beginning of a file name or the beginning of the line starts with something
grep
globally search a regular expression and print - looks through the entire computer and even inside files/folders
Regex Wildcard: [ ]
list of possible values that you define inside the brackets like 1,2 or A-Z, or a-z
Regex Wildcard: |
pipe symbol - Or - assuming this means either or kind of like an if/else
Regex Wildcard: *
will gather any number of characters in a row
cat cal-2019.txt | grep -E "Halloween|Christmas"
would try to find a string matching either Halloween or Christmas - if both are found it will display both. the quotations are just for wrapping the expression - they are not wildcards themselves