The Memory Bank

...for memory blanks

Site Tools


grep

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
grep [2025/05/01 23:52] kengrep [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:**
  
 <code>$ grep "PATTERN1\|PATTERN2" FILE <code>$ grep "PATTERN1\|PATTERN2" FILE
 $ grep -E "PATTERN1|PATTERN2" FILE $ grep -E "PATTERN1|PATTERN2" FILE
 $ grep -e PATTERN1 -e PATTERN2 FILE $ grep -e PATTERN1 -e PATTERN2 FILE
-$ egrep "PATTERN1|PATTERN2" FILE</code> +$ egrep "PATTERN1|PATTERN2" FILE</code>\\ 
- +**Using awk command:**
-=== Using awk command: ===+
  
 <code> <code>
 $ awk '/PATTERN1|PATTERN2/' FILE $ awk '/PATTERN1|PATTERN2/' FILE
-</code> +</code>\\ 
-Using sed command: +**Using sed command:** 
-<code>+<code>\\
 $ sed -e '/PATTERN1/b' -e '/PATTERN2/b' -e d FILE $ sed -e '/PATTERN1/b' -e '/PATTERN2/b' -e d FILE
-</code> +</code>\\
-\\+
 === 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):**
 <code> <code>
 $ grep -E 'PATTERN1.*PATTERN2' FILE $ grep -E 'PATTERN1.*PATTERN2' FILE
-</code> +</code>\\ 
-Using grep command (any order): +**Using grep command (any order):** 
 +<code>
 $ grep -E 'PATTERN1.*PATTERN2|PATTERN2.*PATTERN1' FILE $ grep -E 'PATTERN1.*PATTERN2|PATTERN2.*PATTERN1' FILE
 $ grep 'PATTERN1' FILE | grep 'PATTERN2' $ grep 'PATTERN1' FILE | grep 'PATTERN2'
- +</code>\\ 
-=== Using awk command (exact order): === +**Using awk command (exact order):**
 <code> <code>
 $ awk '/PATTERN1.*PATTERN2/' FILE $ awk '/PATTERN1.*PATTERN2/' FILE
 </code> </code>
-=== Using awk command (any order): === +**Using awk command (any order):**
 <code> <code>
 $ awk '/PATTERN1/ && /PATTERN2/' FILE $ awk '/PATTERN1/ && /PATTERN2/' FILE
-</code> +</code>\\ 
-=== Using sed command (exact order): === +**Using sed command (exact order):**
 <code> <code>
 $ sed '/PATTERN1.*PATTERN2/!d' FILE $ sed '/PATTERN1.*PATTERN2/!d' FILE
-</code> +</code>\\ 
-=== Using sed command (any order): === +**Using sed command (any order):**
 <code> <code>
 $ sed '/PATTERN1/!d; /PATTERN2/!d' FILE $ sed '/PATTERN1/!d; /PATTERN2/!d' FILE
 </code> </code>
-//+\\
 ==== 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:**
 <code> <code>
 $ grep -v 'PATTERN1' FILE $ grep -v 'PATTERN1' FILE
 </code> </code>
-Using awk command: +**Using awk command:** 
 +<code>
 $ awk '!/PATTERN1/' FILE $ awk '!/PATTERN1/' FILE
- +</code> 
-Using sed command: +**Using sed command:** 
 +<code>
 $ sed -n '/PATTERN1/!p' FILE $ sed -n '/PATTERN1/!p' FILE
 +</code>
grep.1746143522.txt.gz · Last modified: (external edit)