File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # grep: Invert Match with -v Flag
2+
3+ The ` -v ` flag inverts the match to show all lines that do _ NOT_ contain the pattern.
4+
5+ ``` bash
6+ # Show all lines except those containing "debug"
7+ grep -v " debug" application.log
8+
9+ # Remove comment lines from config
10+ grep -v " ^#" nginx.conf
11+
12+ # Filter out empty lines
13+ grep -v " ^$" document.txt
14+ ```
15+
16+ ## Practical Examples
17+
18+ ``` bash
19+ # Show all files except README files
20+ ls -la | grep -v README
21+
22+ # Find non-successful HTTP status codes
23+ grep -v " 200 OK" access.log
24+
25+ # Remove verbose logging
26+ tail -f app.log | grep -v " TRACE\|DEBUG"
27+ ```
28+
29+ Filtering test results and system processes:
30+
31+ ``` bash
32+ # Show only failed tests
33+ pytest --tb=short | grep -v " PASSED"
34+
35+ # Find inactive users
36+ grep -v " active" user_status.csv
37+
38+ # Show processes excluding system ones
39+ ps aux | grep -v " ^root"
40+
41+ # Filter out successful builds
42+ grep -v " BUILD SUCCESSFUL" ci_logs.txt
43+ ```
44+
45+ Powerful combinations:
46+
47+ ``` bash
48+ # Remove comments and empty lines
49+ grep -v " ^#" config.ini | grep -v " ^$"
50+
51+ # Exclude multiple patterns
52+ grep -v -e " INFO" -e " DEBUG" system.log
53+
54+ # Case-insensitive exclusion
55+ grep -i -v " success" results.txt
56+ ```
57+
You can’t perform that action at this time.
0 commit comments