Delete all lines not containing string in Sublime
For Sublime use:
1 - CTRL+H
2 - Click Regular Expressions (check ps below)
3 - Find What: ^163.33.74.115.*\n
or ^(?!163.33.74.115).*\n
for inverted matches
4 - Replace With: blank
5 - Click Replace All
GREP ANSWER:
The answer above should work fine, but I'd rather use grep
, which is bundled with linux
and mac
, for windows get it here, i.e.:
1 - All lines except the ones containing 163.33.74.115
:
grep -v 163.33.74.115 original.log > attack.log
2 - All lines containing 163.33.74.115
:
grep 163.33.74.115 original.log > attack.log
Options:
-v, --invert-match select non-matching lines
A quicker option is to just use the 'Find All' option: It selects all the matches for you, so you can copy them.
- Ctrl+F
- Match the lines you want using simple, positive-logic regex:
.*163.33.74.115.*
- Click "Find All"
- Ctrl+C > Open New document > Ctrl+V
The advantage here is that you don't have to remember the regex syntax for negative lookahead -- which is even trickier if you're trying to match on something not at the beginning of the line.