grep:basic_usage
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
grep:basic_usage [2020/08/22 10:46] – created 192.168.1.1 | grep:basic_usage [2020/08/22 11:02] (current) – 192.168.1.1 | ||
---|---|---|---|
Line 19: | Line 19: | ||
---- | ---- | ||
- | ===== Simple | + | ===== Simple |
<code bash> | <code bash> | ||
Line 39: | Line 39: | ||
---- | ---- | ||
+ | |||
+ | ===== Simple Search with Line Numbers ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -n " | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 1:boot | ||
+ | 2:book | ||
+ | 3:booze | ||
+ | 5:boots | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Simple Inverse Search with Line Numbers ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -vn " | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 4:machine | ||
+ | 6:bungie | ||
+ | 7:bark | ||
+ | 8:aaradvark | ||
+ | 9:robots | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | This is the items not found. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Only determine how many lines contain the Search String ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -c " | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 4 | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Determine which files contain the Search String ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -l " | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | This is useful if you are searching through multiple files for the same string. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Ignore Case ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -i " | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Exact Matches Only ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -x " | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | The result in this example will print nothing, because there are no lines that only contain the pattern **boo**. | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Add additional lines of context ===== | ||
+ | |||
+ | <code bash> | ||
+ | grep -A2 " | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | machine | ||
+ | boots | ||
+ | bungie | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | In this example 2 additional lines. | ||
+ | </ | ||
+ | |||
grep/basic_usage.1598093197.txt.gz · Last modified: 2020/08/22 10:46 by 192.168.1.1