68

This probably isn't a VS Code-specific question but it's my tool of choice.

I have a log file with a lot of lines containing the following:

Company.Environment.Security.RightsBased.Policies.RightsUserAuthorizationPolicy

Those are debug-level log records that clutter the file I'm trying to process. I'm looking to remove the lines with that content.

I've looked into Regex but, unlike removing a blank line where you have the whole content in the search criteria (making find/replace easy), here I need to match from line break to line break on some criteria between the two, I think...

What are your thoughts on how criteria like that would work?

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Killnine
  • 5,728
  • 8
  • 39
  • 66

3 Answers3

164

If the criteria is a particular string and you don't want to have to remember regexes, there is a few handy keyboard shortcuts that can help you out. I'm going to assume you're on a Mac.

  1. Cmd-F to open find.
  2. Paste your string.
  3. Opt-Enter to select all of the instances of the string on the page.
  4. Cmd-L to broaden the selection to the entire line of each instance on the page.
  5. Delete/Backspace to remove those lines.
James
  • 773
  • 2
  • 18
  • 29
  • 4
    On Windows, replace "Cmd" with "Ctrl" and this works perfectly. – OLP Jun 01 '20 at 14:20
  • 1
    I also prefer this solution over the regex solution. Matching text with special characters is easier/faster with this solution since you don't have to manually escape each special character. – MKANET Jul 14 '20 at 15:56
  • Hi @James, can you please my this question? https://stackoverflow.com/questions/64365300/how-can-i-remove-unused-imports-declarations-from-the-entire-project-of-react-ty – DevLoverUmar Oct 20 '20 at 03:59
  • Another variant is to highlight one occurrence in the file, right-click, select Change All Occurances then do Ctrl+L and backspace. I guess it's a combination of this answer and the one from Sanket Patel – trademark Feb 22 '21 at 18:10
  • this approach didn't screw up my yaml formatting unlike the regex approach – James Render Aug 20 '21 at 13:26
  • 1
    Thanks!! This worked great on a huge kafka dump file. I use Regex normally but using regex crashed VSCode. btw 3 should be Opt-Enter instead of Alt-Enter – Siraj K Jan 05 '23 at 04:21
80

I think you should be able to just search for ^.*CONTENT.*$\n, where the content is the text you showed us. That is, search on the following pattern:

^.*Company\.Environment\.Security\.RightsBased\.Policies\.RightsUserAuthorizationPolicy.*$\n

And then just replace with empty string.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
6

I have already up-voted answer of @james. But.. still I found one more easy and many feature available extension in VS Code. Here it is

It have much easy options to apply filters.

To match specific case mentioned in question. I am attaching screenshot which display how to use for it. I am posting this for others who come here in search for same issue. (Like I came) enter image description here

Sanket Patel
  • 1,130
  • 14
  • 25
  • useless for larger files, keep showing error when use function "This function requires an active editor" – Mr.Devops Aug 04 '21 at 17:07