User Tools

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 [2020/10/25 13:32] – ↷ Page moved from tool:software:grep to grep rjtgrep [2024/03/02 16:22] (current) – eg of searching for a term, tidying rjt
Line 6: Line 6:
 Basic use is searching a file for a particular term, and grep spitting out each line that term occurs in. Basic use is searching a file for a particular term, and grep spitting out each line that term occurs in.
  
-''grep [term] [file]''+<code bash>grep [term] [file]</code>
  
-With the ''E'' flag you can use the usual regular expressions. So searching for either of two terms:+Search all files in current folder for a term.
  
-''grep -E '[term1]|[term2]' [file]''+<code bash>grep -r -n -i [term] .</code> 
 + 
 +With the ''E'' flag you can use the usual [[regular_expression|regular expressions]]. So searching for either of two terms: 
 + 
 +<code bash>grep -E '[term1]|[term2]' [file]</code>
  
 Otherwise there's also a utility called egrep. Otherwise there's also a utility called egrep.
  
-NB: ''[file]]'' doesn't even have to be a file, you can use wildcard sand things there too.+NB: ''[file]]'' doesn't even have to be a file, you can use wildcards and things there too.
  
-There's probably a beter way to do this, but to search for instances with all terms I use a pip, like:+There's probably a better way to do this, but to search for instances with all terms I use a pipe, like:
  
-''grep '[term1]' [file] | grep '[term2]'''+<code bash>grep '[term1]' [file] | grep '[term2]'</code>
  
 ===== See Also ===== ===== See Also =====
Line 25: Line 29:
   * [[github>phiresky/ripgrep-all]] - Searches more file kinds.   * [[github>phiresky/ripgrep-all]] - Searches more file kinds.
   * [[https://sourceforge.net/projects/multiline-grep/|Multiline Grep]]   * [[https://sourceforge.net/projects/multiline-grep/|Multiline Grep]]
-  * [[form:plaintext]]+  * [[plaintext]]
  
-{{tag>unix linux cli}}+{{tag>cli guide linux plaintext software tool unix}}
grep.1603593163.txt.gz · Last modified: 2020/10/25 13:32 by rjt