Sublime - delete all lines containing specific value
SublimetextSublimetext3Sublimetext Problem Overview
I have a 900mb log file which I can open in SublimeText 3. This file is bloated with lines similar to the following.
10/08/2014 23:45:31:828,Information,,,,ExportManager: ,No records to send and/or not connected
How can I filter out all the lines which contain No records to send and/or not connected
Sublimetext Solutions
Solution 1 - Sublimetext
You can do a regular expression search-and-replace:
Click Find > Replace.
Ensure that the Regular Expression button is pressed.
For the Find What field, put:
^.*No records to send and/or not connected.*\n
Leave the Replace With field empty.
Click Replace All
Solution 2 - Sublimetext
For people that don't want to write a regex - you can just select the search string, hit ctrl+cmd+g
or pick "Quick Find All" from the menu, which will get you selections for each matching string; from there Home
will move every selection cursor to the start of the line, shift+End
will select every matching line, and del, del
will delete all of them.
Multiple cursor editing is fun!
Solution 3 - Sublimetext
i could not get the regex to work so I used Alt-F3 approach from this answer:
- Select string of interest
- Hit Alt+F3 to go into multi-cursor mode on all occurrences (Ctrl+CMD+G on Mac OS X)
- Hit Ctrl+L [see comments] (Cmd+L on Mac)
- Copy-paste selection to another buffer
- Del
Solution 4 - Sublimetext
This is what i found for the windows users:
- Select the string (every line containing this string is to be removed).
- Press ALT+F3 .
- Press Ctrl+L .
- Press Delete .
Solution 5 - Sublimetext
Neither of the regex code suggested above worked in my case, but this did work:
.*(text in question).*
Solution 6 - Sublimetext
A simple way of doing it is:
- 1 Open Sublime Text
- 2 Find => Replace (Ctrl + H)
- 3 in Find write the desired text
- 4 click Find All
- 5 press ctrl + shift + K to remove all the lines where this search is present
This is a quick solution to remove some lines that contains some text
Solution 7 - Sublimetext
I like the manual edition solution, very good.
But.. have you tried to use cat
and grep -v
to filter out the lines and redirect to another file? Maybe better than learning regex.. (personally I always start with regex and end with editing the files myself).
In Windows you use findstr /v
.
So you would do:
# in bash
cat my.log | grep -v "No records to send and/or not connected" > new.log
or
# in cmd
cat my.log | findstr /v "No records to send and/or not connected" > new.log
Solution 8 - Sublimetext
I ran into a similar problem editing a sitemap
This worked for me:
- Copy the last word in the lines that you want to delete
- Find all
- Press delete to delete the entire line
Solution 9 - Sublimetext
Above answers are the correct ways, but if you want to get rid of the rows with even a single string then do,
Find -> Replace -> put ^.*[a-zA-Z]+.*\n
In the find section and keep replace with blank. Hit the replace all button this will delete all the rows with even a single string in it.
Solution 10 - Sublimetext
Find -> Find all (this will mark the lines having the keyword) Then go to Edit->Line->Delete line