-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGREP CLI
56 lines (39 loc) · 2.37 KB
/
GREP CLI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-i, Ignore Case sensitivity.
-a, Equivalent to --binary-files=text.
-v, Ignore.
$, Ends with the Keyword.
--color=always, Always display color highlight.
Searches a file(s) based on a Keyword and then Excludes Keywords:
grep --color=always -a -i ""Keyword1$"\|"Keyword2$"\|"Keyword3$"" "Location & Filename" "Location & Filename" | grep -v 'ExcludeKeyword1\|ExcludeKeyword2\|ExcludeKeyword3'
grep --color=always ""KEYWORD1"\|"KEYWORD2"\|"KEYWORD3"" "Location\FILE.EXTENSION" | tr '\n' ' ' | cut -d ":" -f1
Let's find all occurrences of the word test in DEMO.txt:
grep -n test Demo.txt
Partial Matches:
grep -n test DEMO.txt
Search for full word:
grep -n --word-regexp test DEMO.txt
search for Lines containing test:
grep -Pn 'test\w+' DEMO.txt
search 4 letter word beginning with test:
grep -Pn 'test\w\b' DEMO.txt
Search 3 digit numbers:
grep -Pn '\d\d\d' README.md | head
fixed String:
grep -Pn 'code.' src/data.go | head
Multiple Patterns:
grep -En -e make -e run README.md
Multiple Includes and Excludes:
grep -Pnr --include '*.go' --exclude '*_test.go' 'func'
Searches for beginning of website:
Option 1 - grep --color=always -a -i "http://\|https://" "Location & Filename"
Option 2 - grep -Eo '(http|https)://[^/"]+'
Searches for Ip Addresses:
grep --color=always -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" "Location & Filename"
Searches for All Ip Addresses and remove duplicates:
grep --color=always -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" "Location & Filename" | awk '!x[$0]++'
Search for ip address and remove private IPs:
grep --color=always -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" "Location & Filename" | grep -v -e 10.* -e 192.168.* -e "172\.\(1[6-9]\|2[0-9]\|3[0-1]\)\.*" | awk '!x[$0]++'
Search for ip address and remove private IPs and duplicates:
grep --color=always -a -i -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "Location & Filename" | grep -v -e 10.* -e 192.168.* -e "172\.\(1[6-9]\|2[0-9]\|3[0-1]\)\.*" | awk '!x[$0]++'
Quick IP:
grep -P "(10.|192.168|172.1[6-9].|172.2[0-9].|172.3[01].).*