Skip to content

Commit 69efff3

Browse files
committed
feat: add grep -v falg
1 parent 0d0e310 commit 69efff3

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+

0 commit comments

Comments
 (0)