hello!
want to delete all lines in a logfile that contain a special word.
but i just found the replace function -> but i want to delete all lines that contain the special word.
please help, thanks
ps: i used forum search, but did not find a matching topic
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> Since this thread has been resurrected and the discussion seems to be going strong, let me add my suggestion.
> Once more, Simple Script comes to the rescue (Yes, I'm the author of the Simple Script plugin, and yes, I'm making it sound more exciting than it really is).
> It's a one-line script if you use the CutLinesWith or CutLinesWithout functions. Keep in mind that it puts those lines on the clipboard, but if you don't care about that, then it should work fine.
> For example:
> CutLinesWithout("ABC")
> removes all lines that don't include the string ABC in them and puts them on the clipboard.
There is no need to use a difficult method with a plugin at all.
Use advanced Find/Replace (CTRL+R is more clear than ^R for someone who has no clue).
In the Find field type CTRL+M twenty nine times.
In the Replace field type CTRL+M eight times, then some specific identifier like #idiot# and then CTRL+M another 38 hundred times.
This also avoids the risk of crashing your computer with a plugin. Plugins are lightweight trojans for horses.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You might try the TextFX Viz menu. Copy the special word to the clipboard, then use the TextFX Viz menu items to either show lines with, or hide lines without, (clipboard) text. You can then delete the visible lines if you are showing lines with the special word, or delete the invisible lines if you are hiding those lines. --Joel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using TextFX Viz as described doesn't seem to work.
Try this:
1) Create a window with this:
ABC
DEF
ABCDEF
2) Select ABC and then ctrl-C to copy it to clipboard
3) TextFX Viz->Hide all lines containing clipboard text (this should hide 'DEF')
4) TextFX Vix->Delete Invisible Selection
I presume step 4 should delete the line DEF but it doesn't.
(How does one show all lines? I switch from and then back to the window to do that --when I do it, the line with DEF is back).
What am I doing wrong?
I'm using version 4.7.5
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Use something in the find field like
^.*typeyourwordhere.*$
where typeyourwordhere is the word you're looking for. Leave the replace field blank.
You could also add spaces before and after the word or any other characters making the expression match even better the exact lines.
This will result in all lines containing the word to become empty.
You can then remove them, if desired.
You could also enter a special marker text in the replace field and remove all those lines in a second pass, while replacing with regular expressions turned off. You could simply achieve this by selecting the first line with the special marker completely. Go to the start of the first line containing it. Hold the SHIFT button down and press the CursorDown key. Then press CTRL+H to replace occurrences of this line by an empty replace field.
Does this work?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't think the referenced page describes a way of doing what I want, which is 'delete all lines that DO NOT contains a specific substring'. Is there a way to do that?
I thought TextFX Viz tools would do it (as posted earlier in this thread) but they don't seem to do what I expect from their description (ie., there's a bug or I don't understand the tool).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Make empty all the lines I want gone and then use TextFX->Text Edit->Delete Blank Lines
But if the file already had blank lines I wanted to keep, then
use the Hex-Editor plugin (or advanced find replace) to insert some unique character at the beginning of every line
(by replacing the end-of-line chars with the end-of-line chars + unique char), and then
use a regular expression to make blank all the lines I wanted gone, and then
TextFX->Text Edit->Delete Blank Lines
For example, in Advanced Find/Replace (ie control-R, ie ^R) and without regex checked:
Find: ^M
Replace: ^M!
and touch up to get '!' at beginning of every line in file, and then (with regex checked):
Find: (.*special word.*)
Replace:
now all desired lines to delete are blank, and then
TextFX->Text Edit->Delete Blank Lines
now restore original blank lines (w regex):
Find: ^!
Replace:
hope this helps the nobody from a year ago :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is no need to use a difficult method with the Hex Editor at all.
If you want to keep blank lines, simply replace them first by some unique text.
Use advanced Find/Replace (CTRL+R is more clear than ^R for someone who has no clue).
In the Find field type CTRL+M twice.
In the Replace field type CTRL+M, then some specific identifier like #blank-line# and then CTRL+M again.
Replace all occurrences.
No remove all lines using a regular expression as explained before.
Then, finally, restore all special lines to blank lines again.
In advanced Find/Replace, turn off regular expressions.
Fill the Find field with the Replace field of the action above.
Fill the Replace field with typing CTRL+M twice.
Replace all occurrences.
This also avoids the risk of removing !'s in front of lines, that were already there before the "magic replacement trick".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since this thread has been resurrected and the discussion seems to be going strong, let me add my suggestion.
Once more, Simple Script comes to the rescue (Yes, I'm the author of the Simple Script plugin, and yes, I'm making it sound more exciting than it really is).
It's a one-line script if you use the CutLinesWith or CutLinesWithout functions. Keep in mind that it puts those lines on the clipboard, but if you don't care about that, then it should work fine.
For example:
CutLinesWithout("ABC")
removes all lines that don't include the string ABC in them and puts them on the clipboard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hello!
want to delete all lines in a logfile that contain a special word.
but i just found the replace function -> but i want to delete all lines that contain the special word.
please help, thanks
ps: i used forum search, but did not find a matching topic
> Since this thread has been resurrected and the discussion seems to be going strong, let me add my suggestion.
> Once more, Simple Script comes to the rescue (Yes, I'm the author of the Simple Script plugin, and yes, I'm making it sound more exciting than it really is).
> It's a one-line script if you use the CutLinesWith or CutLinesWithout functions. Keep in mind that it puts those lines on the clipboard, but if you don't care about that, then it should work fine.
> For example:
> CutLinesWithout("ABC")
> removes all lines that don't include the string ABC in them and puts them on the clipboard.
There is no need to use a difficult method with a plugin at all.
Use advanced Find/Replace (CTRL+R is more clear than ^R for someone who has no clue).
In the Find field type CTRL+M twenty nine times.
In the Replace field type CTRL+M eight times, then some specific identifier like #idiot# and then CTRL+M another 38 hundred times.
This also avoids the risk of crashing your computer with a plugin. Plugins are lightweight trojans for horses.
You might try the TextFX Viz menu. Copy the special word to the clipboard, then use the TextFX Viz menu items to either show lines with, or hide lines without, (clipboard) text. You can then delete the visible lines if you are showing lines with the special word, or delete the invisible lines if you are hiding those lines. --Joel
Using TextFX Viz as described doesn't seem to work.
Try this:
1) Create a window with this:
ABC
DEF
ABCDEF
2) Select ABC and then ctrl-C to copy it to clipboard
3) TextFX Viz->Hide all lines containing clipboard text (this should hide 'DEF')
4) TextFX Vix->Delete Invisible Selection
I presume step 4 should delete the line DEF but it doesn't.
(How does one show all lines? I switch from and then back to the window to do that --when I do it, the line with DEF is back).
What am I doing wrong?
I'm using version 4.7.5
How about using a regular expression for this?
Use something in the find field like
^.*typeyourwordhere.*$
where typeyourwordhere is the word you're looking for. Leave the replace field blank.
You could also add spaces before and after the word or any other characters making the expression match even better the exact lines.
This will result in all lines containing the word to become empty.
You can then remove them, if desired.
You could also enter a special marker text in the replace field and remove all those lines in a second pass, while replacing with regular expressions turned off. You could simply achieve this by selecting the first line with the special marker completely. Go to the start of the first line containing it. Hold the SHIFT button down and press the CursorDown key. Then press CTRL+H to replace occurrences of this line by an empty replace field.
Does this work?
See "Some more "advanced" mass replacement/delete?" on the Help forum:
http://sourceforge.net/forum/forum.php?thread_id=1823297&forum_id=331754
You can find this message by entering "delete+line" in the search field before the button.
I don't think the referenced page describes a way of doing what I want, which is 'delete all lines that DO NOT contains a specific substring'. Is there a way to do that?
I thought TextFX Viz tools would do it (as posted earlier in this thread) but they don't seem to do what I expect from their description (ie., there's a bug or I don't understand the tool).
Perhaps you don't understand the tool.
Are you the starter of this thread?
BTW: How about using MACRO?
- Search for your word "AB" in find window - now it is available via F3.
- Go to top of document again.
- Start a record:
o Press F3
o Press CTRL+L
o Stop record
Now do start a marcro playback until documents end.
Best Regards
Jens
Here's what I would have done last March -
Make empty all the lines I want gone and then use TextFX->Text Edit->Delete Blank Lines
But if the file already had blank lines I wanted to keep, then
use the Hex-Editor plugin (or advanced find replace) to insert some unique character at the beginning of every line
(by replacing the end-of-line chars with the end-of-line chars + unique char), and then
use a regular expression to make blank all the lines I wanted gone, and then
TextFX->Text Edit->Delete Blank Lines
For example, in Advanced Find/Replace (ie control-R, ie ^R) and without regex checked:
Find: ^M
Replace: ^M!
and touch up to get '!' at beginning of every line in file, and then (with regex checked):
Find: (.*special word.*)
Replace:
now all desired lines to delete are blank, and then
TextFX->Text Edit->Delete Blank Lines
now restore original blank lines (w regex):
Find: ^!
Replace:
hope this helps the nobody from a year ago :-)
There is no need to use a difficult method with the Hex Editor at all.
If you want to keep blank lines, simply replace them first by some unique text.
Use advanced Find/Replace (CTRL+R is more clear than ^R for someone who has no clue).
In the Find field type CTRL+M twice.
In the Replace field type CTRL+M, then some specific identifier like #blank-line# and then CTRL+M again.
Replace all occurrences.
No remove all lines using a regular expression as explained before.
Then, finally, restore all special lines to blank lines again.
In advanced Find/Replace, turn off regular expressions.
Fill the Find field with the Replace field of the action above.
Fill the Replace field with typing CTRL+M twice.
Replace all occurrences.
This also avoids the risk of removing !'s in front of lines, that were already there before the "magic replacement trick".
Since this thread has been resurrected and the discussion seems to be going strong, let me add my suggestion.
Once more, Simple Script comes to the rescue (Yes, I'm the author of the Simple Script plugin, and yes, I'm making it sound more exciting than it really is).
It's a one-line script if you use the CutLinesWith or CutLinesWithout functions. Keep in mind that it puts those lines on the clipboard, but if you don't care about that, then it should work fine.
For example:
CutLinesWithout("ABC")
removes all lines that don't include the string ABC in them and puts them on the clipboard.