Sublime - delete all lines containing specific value

108,029

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:

https://superuser.com/questions/452189/how-can-i-filter-a-file-for-lines-containing-a-string-in-sublime-text-2/598999#598999

  1. Select string of interest
  2. Hit Alt+F3 to go into multi-cursor mode on all occurrences (Ctrl+CMD+G on Mac OS X)
  3. Hit Ctrl+L [see comments] (Cmd+L on Mac)
  4. Copy-paste selection to another buffer
  5. Del

Solution 4

This is what i found for the windows users:

  1. Select the string (every line containing this string is to be removed).
  2. Press ALT+F3 .
  3. Press Ctrl+L .
  4. Press Delete .

Solution 5

Neither of the regex code suggested above worked in my case, but this did work:

.*(text in question).*
Share:
108,029
energ1ser
Author by

energ1ser

#SOreadytohelp

Updated on August 19, 2021

Comments

  • energ1ser
    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
    Conspicuous Compiler over 9 years
    Two 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
    Navigatron over 9 years
    The 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
    MiB about 9 years
    This 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
    Chnossos about 9 years
    You can replace steps 3 and 4 with CTRL + L, which expands selections to whole lines, including line break.
  • black panda
    black panda almost 9 years
    Is ctrl+cmd+g the same as ctrl+alt+g on Windows? I couldn't get this to work
  • 7caifyi
    7caifyi over 8 years
    @black panda For windows "Quick Find All" is alt+f3 - Thanks Leonid +1
  • Koray Tugay
    Koray Tugay over 8 years
    If you are like me and you do not have a Home button, you can also use CMD + <- (left arrow)
  • Koray Tugay
    Koray Tugay almost 8 years
    You can also use cmd + L to expand selection to line.
  • Cyril Duchon-Doris
    Cyril Duchon-Doris over 7 years
    For 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
    user over 7 years
    It 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
    Przemek D almost 7 years
    This 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
    Avik over 6 years
    If 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
    bryc over 6 years
    Works for me, If you need multiple matches like I did, use | like so: .*(a).*|.*(b).*|.*(c).*
  • Y-B Cause
    Y-B Cause over 6 years
    Imma try this with my 26 000 000 lines file :')