classnotes:rh134:bash:regex
Regular Expressions
They are a pattern matching tool
THey are used by tools like grep awk sed etc
You can question the output to see if pattern was found using $?
grep
stands for global regular expression print
it will highlight the pattern if its found
command looks like
greo pattern file
exit codes are using $?
| 0 | pattern was found |
|---|---|
| 1 | pattenr not found |
| 2 | file not found |
grep options
| -n | shows you line where pattern was found | grep -n root /etc/passwd |
|---|---|---|
| -c | number of lines that had the pattern | grep -c root /etc/passwd |
| ^ | look at beginning of line only | grep ^pattern /etc/passwd |
| $ | look at end of line | grep bash$ /etc/passwd |
| -E | match to more than one regular expresion | grep -E 'student|devops|lolly' /etc/passwd |
| ^[^#] | give every line that does not begin with a # | grep ^[^#] /etc/passwd |
THere are loads more options
classnotes/rh134/bash/regex.txt · Last modified: by 127.0.0.1
