This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| grep [2025/05/01 23:52] – ken | grep [2026/01/16 03:37] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| Find all the lines of a file, that match any of provided patterns. | Find all the lines of a file, that match any of provided patterns. | ||
| - | === Using grep and egrep commands: | + | **Using grep and egrep commands:** |
| < | < | ||
| $ grep -E " | $ grep -E " | ||
| $ grep -e PATTERN1 -e PATTERN2 FILE | $ grep -e PATTERN1 -e PATTERN2 FILE | ||
| - | $ egrep " | + | $ egrep " |
| - | + | **Using awk command:** | |
| - | === Using awk command: | + | |
| < | < | ||
| $ awk '/ | $ awk '/ | ||
| - | </ | + | </ |
| - | Using sed command: | + | **Using sed command:** |
| - | < | + | < |
| $ sed -e '/ | $ sed -e '/ | ||
| - | </ | + | </ |
| - | \\ | + | |
| === GREP AND: Match Multiple Patterns === | === GREP AND: Match Multiple Patterns === | ||
| Line 32: | Line 30: | ||
| Use one of the following commands to find and print all the lines of a file, that match multiple patterns.\\ | Use one of the following commands to find and print all the lines of a file, that match multiple patterns.\\ | ||
| \\ | \\ | ||
| - | === Using grep command (exact order): | + | **Using grep command (exact order):** |
| < | < | ||
| $ grep -E ' | $ grep -E ' | ||
| - | </ | + | </ |
| - | Using grep command (any order): | + | **Using grep command (any order):** |
| + | < | ||
| $ grep -E ' | $ grep -E ' | ||
| $ grep ' | $ grep ' | ||
| - | + | </ | |
| - | === Using awk command (exact order): | + | **Using awk command (exact order):** |
| < | < | ||
| $ awk '/ | $ awk '/ | ||
| </ | </ | ||
| - | === Using awk command (any order): | + | **Using awk command (any order):** |
| < | < | ||
| $ awk '/ | $ awk '/ | ||
| - | </ | + | </ |
| - | === Using sed command (exact order): | + | **Using sed command (exact order):** |
| < | < | ||
| $ sed '/ | $ sed '/ | ||
| - | </ | + | </ |
| - | === Using sed command (any order): | + | **Using sed command (any order):** |
| < | < | ||
| $ sed '/ | $ sed '/ | ||
| </ | </ | ||
| - | // | + | \\ |
| ==== GREP NOT: Negative Matching ==== | ==== GREP NOT: Negative Matching ==== | ||
| - | |||
| Find and print all the lines, that do not match a pattern.\\ | Find and print all the lines, that do not match a pattern.\\ | ||
| - | Using grep command: | + | **Using grep command:** |
| < | < | ||
| $ grep -v ' | $ grep -v ' | ||
| </ | </ | ||
| - | Using awk command: | + | **Using awk command:** |
| + | < | ||
| $ awk ' | $ awk ' | ||
| - | + | </ | |
| - | Using sed command: | + | **Using sed command:** |
| + | < | ||
| $ sed -n '/ | $ sed -n '/ | ||
| + | </ | ||