Delete Individual Lines in Multiple Files based on a List
I have a text file with 400+ lines of unique text, similar to this:
Each of these lines (records) matches another line in one of 5 additional open files across the tabs, but I cannot confirm in which file each line resides, therefore I can search a unique line and find it in all open files and then double click on the record found and go to that file to delete it, however this is a laborious task when done 400+ times and I know Notepad++ would be able to delete these records automatically, I just don’t know how.
Whay I would like is a way of searching each of the 400+ records in the one file and deleting each line in any of the other 5 files, leaving 5 adjusted files and the original ‘search’ file.
In the meantime I will continue to delete the records manually, but I know you guys are amazing at coming up with something I can use.
I would try * a technique like the one shown here. You can use Replace All in All Opened Documents to do a single-button action, but unfortunately I think you are going to have to copy your lookup data table to the bottom of each file temporarily (5 files, not a huge deal…), something like this:
------------------------------------------------- doc:EMPLOYEEFILE.5C5D259F084B11DC93FF00163505A2EF doc:EMPLOYEEFILE.5C0C2040084B11DC93FF00163505A2EF doc:EMPLOYEEFILE.5BBD63D1084B11DC93FF00163505A2EF doc:EMPLOYEEFILE.5B5BBBA2084B11DC93FF00163505A2EF doc:EMPLOYEEFILE.3715DD892E6411DDA81300163505A2EF
Note also that I have put a “delimiter” line of dashes in the file, right above the lookup-table. Hopefully this type of line does not occur elsewhere in your data.
After doing this, if you execute the following, it may work:
Find what zone:
Replace with zone: make sure this is empty
Search mode: Regular expression
Action: Replace All in All Opened Documents button
It works by seeking a line with correct formatting above the line of dashes, and attempting to find the same line below the line of dashes. If it is able to find it, the empty replacement will effectively remove the original line.
*I say try above because if we are talking “really big data” here, the this approach may fail without some further analysis and tweaking.
Scott, Thank you. I knew there would be a way and I almost knew it would be something in a regular expression, but only gods like yourself would know what to do. I really like the idea of a delimeter and then using the search to match any above and below the line.
I did not get the chance to try this (although I can’t see why it wouldn’t work) as I thought of an alternative, which was to use Excel and a formula. I managed to open each of my 5 files in one workbook with seperate tabs and use a formula to look at a control tab to find any matches. I think it’s pretty much the same thing as your suggestion, just using vba and not regex.
I thank you for your efforts