grep:basic_usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
grep:basic_usage [2020/08/22 10:48] – 192.168.1.1 | grep:basic_usage [2020/08/22 11:02] (current) – 192.168.1.1 | ||
---|---|---|---|
Line 57: | Line 57: | ||
<WRAP info> | <WRAP info> | ||
**NOTE: | **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.1598093321.txt.gz · Last modified: 2020/08/22 10:48 by 192.168.1.1