User Tools

Site Tools


grep:basic_usage

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:basic_usage [2020/08/22 10:53] 192.168.1.1grep:basic_usage [2020/08/22 11:02] (current) 192.168.1.1
Line 100: Line 100:
 **NOTE:**  grep prints out 4 as there are 4 occurrences of the word **boo**. **NOTE:**  grep prints out 4 as there are 4 occurrences of the word **boo**.
 </WRAP> </WRAP>
 +
 +----
 +
 +===== Determine which files contain the Search String =====
 +
 +<code bash>
 +grep -l "boo" *
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The **-l** option prints only the filenames of files in the query that have lines that match the search string.
 +
 +This is useful if you are searching through multiple files for the same string.
 +</WRAP>
 +
 +----
 +
 +===== Ignore Case =====
 +
 +<code bash>
 +grep -i "BOO" filename
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The **-i** option will treat upper and lower case as equivalent while matching the search string.
 +</WRAP>
 +
 +----
 +
 +===== Exact Matches Only =====
 +
 +<code bash>
 +grep -x "boo" filename
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The **-x** option looks for eXact matches only.
 +
 +The result in this example will print nothing, because there are no lines that only contain the pattern **boo**.
 +</WRAP>
 +
 +----
 +
 +===== Add additional lines of context =====
 +
 +<code bash>
 +grep -A2 "mach" filename
 +</code>
 +
 +returns:
 +
 +<code bash>
 +machine
 +boots
 +bungie
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The **A** option will print out the search string plus a number of additional lines.
 +
 +In this example 2 additional lines.
 +</WRAP>
 +
  
grep/basic_usage.1598093582.txt.gz · Last modified: 2020/08/22 10:53 by 192.168.1.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki