CPU_ALL
ZZZZ
etc.
So I fired up Eclipse, opened the file, and opened Find/Replace dialog box. In the dialog, I tried to replace:
^\b(?!CPU_ALL)(?!ZZZZ)\w+\b.*$
with
Blank
So Eclipse find all strings that does not start with CPU_ALL nor ZZZZ and replaced those lines with space.
I was able to do another Replace of ^\n$ with Blank, so all blank lines got removed. But some how Eclipse complaint I had incompatible end of lines. So I opened the text file with my favorite text editor Notepad++ and ran its "Remove blank lines" plugin to get the job done.
The key here is
(?!CPU_ALL)
which matches string that does not start with "CPU_ALL".
And another
(?!ZZZZ)right after allows me to exclude another string.
Cheers!
1 comment:
Hi Li,
I come across this task a lot, I usually prefer doing that with command line tools, in case I'll need to repeat the same task more than once, or even automate it.
For the specific case your describing, I would go with:
cat log.txt | grep -E "(CPU_ALL|ZZZ)" > filtered.txt
For text substitutions sed or awk do a great job.
Post a Comment