Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all lines containing a specific string

I have a big file and I want to remove all the lines that have the word date

For example:

{
  date: 10291992
  stuff: stuff
  ...
},
{
  date: 02171995
  stuff: stuff
  ...
},

...

So I want to remove all the lines that contains the word date but since each date has a different date, I can't just ctrl f and replace it. I was reading that putting ^.* in the front but it didn't work for me.

I'm currently using Sublime Text 3.

Thanks.

like image 764
user3128376 Avatar asked Jan 20 '15 00:01

user3128376


2 Answers

All you need to do is open the Find dialog (Find -> Find...), search for date, hit Find All to select all instances of your search pattern, then select Selection -> Expand Selection to Line. Hit Delete and you're all done.

like image 142
MattDMo Avatar answered Oct 08 '22 17:10

MattDMo


I tried to follow the accepted answer but found it wasn't working for me: the Expand Selection to Line button was not expanding the selection for all the matched lines.

What did work, though, was to switch to regular expression mode (the *. button on the left of the Find menu) and do a search for

\n.+date.+

replacing it with an empty string. This removes the entire line (i.e., doesn't leave an empty line in its place).

like image 30
Kurt Peek Avatar answered Oct 08 '22 19:10

Kurt Peek