Identify and Delete all lines starting with # in Notepad++
Today I was having to search out and filter out many lines in a rather huge hosts file. There were a lot of lines that had been hashed out, I wanted to remove all of these so I could actually see what it was I was after. Once I would have all the lines left then I know what I need to look into.
Once I had opened the file, first off I wanted to just identify how many rows there were, first off you go to Find then place in the following regular expression (in the example on my screen shot below, I was after lines that started with a # or a ;, so the regular expression to identify all lines with a #.
The ^ means the beginning of the line, the # inside the brackets is what you are looking for the line to begin with, then .* means match anything else on the line. One other thing is to ensure you select Regular Expression at the bottom, you can see I have highlighted them with arrows.
This will just show the lines, it will show them in a window at the bottom. If you want them all removed then select replace.
So all you do is leave the Replace with blank and it will delete all the lines that start with a # or a ; in this case. This will leave you with lots of blank lines, you can easily remove these.
Go to Edit -> Line Operations -> Remove Empty Lines, or Remove Empty Lines (Containing Blank Characters).
So for this I had a file with over 5000 lines, within 30 seconds I had the actual real 380 lines that I needed and I know I need to action, much easier than try to scroll down to find the lines.
I am always interested in feedback so please feel free to add any comments, or you can mail me here. If you would like to submit a quick tip with full credit and links back to your site then also feel free to contact me.