Delete a line based on content - Please Help :-)
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Delete a line based on content - Please Help :-)
Hi Folks;
I need to trim down an 80 meg log file so what I need to do is delete every line that contains the text:
192.168.1.1
Can anyone give me a step by step on how to automate deleting all lines that contain 192.168.1.1 ?
Thanks!
I need to trim down an 80 meg log file so what I need to do is delete every line that contains the text:
192.168.1.1
Can anyone give me a step by step on how to automate deleting all lines that contain 192.168.1.1 ?
Thanks!
Best Regards;
Marvin Miller
Marvin Miller
- talleyrand
- Posts: 624
- Joined: Mon Jul 21, 2003 6:56 pm
- Location: Kansas City, MO, USA
- Contact:
I've had a few glasses of stout so pardon any mistakes but you are looking to perform a search and replace. Your search criteria will be a regular expression. The expression you probably want to use is
.*192\.168\.1\.1.*
That ought to find any line that has 192.168.1.1 in it, be it at the begining, middle or end.
The replacement expression is blank, empty.
If this ends up leaving two blank lines, run an second search and replace for \n\n and replace it with \n. Someone more clever than I will post a better solution but those ought to work. Also, if they do work, make a macro and then you can play the solution in any of your log files to clean them up.
.*192\.168\.1\.1.*
That ought to find any line that has 192.168.1.1 in it, be it at the begining, middle or end.
The replacement expression is blank, empty.
If this ends up leaving two blank lines, run an second search and replace for \n\n and replace it with \n. Someone more clever than I will post a better solution but those ought to work. Also, if they do work, make a macro and then you can play the solution in any of your log files to clean them up.
I choose to fight with a sack of angry cats.
Hi talleyrand;
Thanks for the reply! I tried copying and pasting the expression .*192\.168\.1\.1.* in TextPad but it says that it can't find it. I've verified that I have the right text file with the 192.168.1.1 lines in them
All I did was copy and paste it into the search and replace box and then told it to do it. It can't find it so I suspect there might be something wrong with the expression? I don't know much about TextPad so you might have to forgive me if I messed it up somehow
Thanks for the reply! I tried copying and pasting the expression .*192\.168\.1\.1.* in TextPad but it says that it can't find it. I've verified that I have the right text file with the 192.168.1.1 lines in them
All I did was copy and paste it into the search and replace box and then told it to do it. It can't find it so I suspect there might be something wrong with the expression? I don't know much about TextPad so you might have to forgive me if I messed it up somehow
Best Regards;
Marvin Miller
Marvin Miller
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
I did find one issue though, in the file the lines with 192.168.1.1 are not all back to back. For instance, in most cases there's 50 lines in a row and then some other lines and then 3 lines in a row etc.
So after running the command to delete the lines my log files have various gaps in them. So in part there might be as much as 100 lines missing and in another there may be only 3 missing.
I did try and run the command to remove the blank lines but it only seemed to remove certain ones.
If there's an easy solution that would be great but at this point it's more cosmetic then anything. The key thing is trimming out the 192.168.1.1 lines and with everyone's help that's been accomplished
So after running the command to delete the lines my log files have various gaps in them. So in part there might be as much as 100 lines missing and in another there may be only 3 missing.
I did try and run the command to remove the blank lines but it only seemed to remove certain ones.
If there's an easy solution that would be great but at this point it's more cosmetic then anything. The key thing is trimming out the 192.168.1.1 lines and with everyone's help that's been accomplished
Best Regards;
Marvin Miller
Marvin Miller
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
If you follow my suggestion, the job is done in a single step. It deletes each line containing the IP address, including the terminating new line character. No empty lines are left.
If a file has sequences of empty lines, that is, sequences of new line characters, and you replace every pair of new lines with a single one, you halve the number in each sequence of new lines. So you have to perform the replacement repeatedly. You can't replace \n+ by \n; that is a deficiency of the regex engine used by TextPad.
If a file has sequences of empty lines, that is, sequences of new line characters, and you replace every pair of new lines with a single one, you halve the number in each sequence of new lines. So you have to perform the replacement repeatedly. You can't replace \n+ by \n; that is a deficiency of the regex engine used by TextPad.
Hi Ben;
My bad - I didn't notice that you had appended the \n at the end of your suggestion. I've been spending way too much time staring at the screen over the last few days so it's time for a break
I'll do it that way on my next logfile. It was mentioned to create a mackerel to make this easier? What would that do and how would it work?
My bad - I didn't notice that you had appended the \n at the end of your suggestion. I've been spending way too much time staring at the screen over the last few days so it's time for a break
I'll do it that way on my next logfile. It was mentioned to create a mackerel to make this easier? What would that do and how would it work?
Best Regards;
Marvin Miller
Marvin Miller
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
Mackerel is good! I like mackerel. Some may tell you to say macro, but take no notice.
Here's how to record a fish that might do the trick :
Macro | Record (<Ctrl+Shift+R>)
Search | Replace... (<F8>)
.*192\.168\.1\.1.*\n
<Tab>
<Del>
[Make sure that Regular expression is selected.]
Replace All
<Esc>
Macro | Stop Recording (Ctrl+Shift+R)
At this point you have a temporary fish; you can save it permanently if you wish.
You can replay the temporary fish with Macro | Playback (Ctrl+R).
You can save it permanently (unless you've overwritten it) with Macro | Save....
Look in the help under How to... | Use Keystroke Macros.
Here's how to record a fish that might do the trick :
Macro | Record (<Ctrl+Shift+R>)
Search | Replace... (<F8>)
.*192\.168\.1\.1.*\n
<Tab>
<Del>
[Make sure that Regular expression is selected.]
Replace All
<Esc>
Macro | Stop Recording (Ctrl+Shift+R)
At this point you have a temporary fish; you can save it permanently if you wish.
You can replay the temporary fish with Macro | Playback (Ctrl+R).
You can save it permanently (unless you've overwritten it) with Macro | Save....
Look in the help under How to... | Use Keystroke Macros.