Sublime - delete all lines containing specific value
Solution 1
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
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
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
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
Neither of the regex code suggested above worked in my case, but this did work:
.*(text in question).*
![energ1ser](https://i.stack.imgur.com/Mfef8.jpg?s=256&g=1)
Comments
-
energ1ser almost 3 years
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
-
Conspicuous Compiler over 9 yearsTwo things: (1) You can link to an individual answer like this (2) You should summarize the other answer here (and specialize it to answer this question as appropriate).
-
Navigatron over 9 yearsThe full stop/period at the end is important, without it, it won't work. Alternatively, you could use this:
^.*No records to send and/or not connected\S.*$
-
MiB about 9 yearsThis is a very useful more generalized tip. My objective was to delete all lines containing a string. I ended up selecting one instance of it then used "QuickFind" with the shortcut
Ctrl+Cmd+G
as Leonid suggests for selecting all those strings. After this I could go directly to "Delete Line"Ctrl-Shift-K
and surgically all the lines with this string were removed in an instant. Sublime Text really is the best text editor I've ever used. -
Chnossos about 9 yearsYou can replace steps 3 and 4 with
CTRL + L
, which expands selections to whole lines, including line break. -
black panda almost 9 yearsIs ctrl+cmd+g the same as ctrl+alt+g on Windows? I couldn't get this to work
-
7caifyi over 8 years@black panda For windows "Quick Find All" is alt+f3 - Thanks Leonid +1
-
Koray Tugay over 8 yearsIf you are like me and you do not have a Home button, you can also use CMD + <- (left arrow)
-
Koray Tugay almost 8 yearsYou can also use cmd + L to expand selection to line.
-
Cyril Duchon-Doris over 7 yearsFor those like me cursed by a MAC key scheme :
Ctrl+Cmd+G
to for multi-cursor on all occurences,Cmd+L
to expand lines, and the usual copy/paste -
user over 7 yearsIt will let empty lines on your code, is that you want to? If not, add
\n
or$
at the end:.*(text in question).*\n
-
Przemek D almost 7 yearsThis solution is the only feasible one if you're operating on a large file. My machine got stuck for several minutes when I did
Ctrl+Shift+K
with 200,000 lines selected. -
Avik over 6 yearsIf lines are having "abc/xyz/something" like structure, to use regex add ' \ '. For example if we have to search anything in between abc/ and /something then the expression will be : abc/\.*.*\/something
-
bryc over 6 yearsWorks for me, If you need multiple matches like I did, use
|
like so:.*(a).*|.*(b).*|.*(c).*
-
Y-B Cause over 6 yearsImma try this with my 26 000 000 lines file :')