Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

notepad++ deleting all text except what matches regex

I have a text file with information about a recording, including track numbers and names, and I want to delete all the other text except the track number and track names. For example the text file looks like this:

text text text text
text text text text text text text text
text text text text text text text text text text text text
text text text text
text text text text text text text text
text text text text 
text text text text text text text text text text text text text text text text 
text text text text text text text text 
text text text text 

d1t01 - trackname

d1t02 - trackname

d1t03 - trackname

d1t04 - trackname

d1t05 - trackname

d1t06 - trackname

d1t07 - trackname

d1t08 - trackname

d1t09 - trackname

d1t10 - trackname

d1t11 - trackname

text text text text
text text text text text text text text
text text text text text text text text text text text text
text text text text
text text text text text text text text
text text text text 
text text text text text text text text text text text text text text text text 
text text text text text text text text 
text text text text 

I want to be left with just this:

d1t01 - trackname

d1t02 - trackname

d1t03 - trackname

d1t04 - trackname

d1t05 - trackname

d1t06 - trackname

d1t07 - trackname

d1t08 - trackname

d1t09 - trackname

d1t10 - trackname

d1t11 - trackname

I figured out how to match the beginning of the line with this regex:

d[0-9]+t[0-9]+[0-9]+ -

But I can't figure out how to delete the rest of the "text" and only leave those lines. I also need it to delete the "returns" and not be left with any blank lines in the text file.

Thank you!

like image 410
cisconethead Avatar asked Jun 05 '14 03:06

cisconethead


People also ask

Does Notepad support regex?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.


1 Answers

Step 1 - Match lines. Find dialog > Mark tab, you can bookmark lines that match.

Step 2 - Remove lines bookmarked OR Remove lines not bookmarked. Search > Bookmark > Remove Unmarked Lines or Remove Bookmarked lines

like image 142
Gaurav Avatar answered Nov 13 '22 13:11

Gaurav