Sublime - delete all lines containing specific value


Sublimetext 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:

  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 - Sublimetext

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 - 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


# 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:

  1. Copy the last word in the lines that you want to delete
  2. Find all
  3. 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


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionenerg1serView Question on Stackoverflow
Solution 1 - SublimetextJonathan AquinoView Answer on Stackoverflow
Solution 2 - SublimetextLeonid ShevtsovView Answer on Stackoverflow
Solution 3 - SublimetextdenfromufaView Answer on Stackoverflow
Solution 4 - SublimetextPrashant GoelView Answer on Stackoverflow
Solution 5 - SublimetextMagnusView Answer on Stackoverflow
Solution 6 - SublimetextShuherView Answer on Stackoverflow
Solution 7 - SublimetextWesternGunView Answer on Stackoverflow
Solution 8 - SublimetextPete VarleyView Answer on Stackoverflow
Solution 9 - Sublimetextshubham mishraView Answer on Stackoverflow
Solution 10 - SublimetextPratyushView Answer on Stackoverflow