Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime - delete all lines containing specific value

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

like image 463
energ1ser Avatar asked Aug 11 '14 22:08

energ1ser


People also ask

How do you delete multiple lines in Sublime Text?

To select multiple regions using the keyboard, select a block of text, then press Ctrl+Shift+L to split it into one selection per line. When you're done with using multiple selections, just press Ctrl+K to trim all but the first.

How do you delete a line in Sublime Text?

To quickly delete a line in your code, place your cursor anywhere in the line and hit Ctrl–Shift–K (Mac and Windows).


3 Answers

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

like image 168
Jonathan Aquino Avatar answered Oct 23 '22 07:10

Jonathan Aquino


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!

like image 73
Leonid Shevtsov Avatar answered Oct 23 '22 08:10

Leonid Shevtsov


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
like image 69
denfromufa Avatar answered Oct 23 '22 07:10

denfromufa