dantheman
dantheman

Reputation: 273

How can I replace only specific newline's in my text file?

I have a text file that looks like this:

#EXTINF:0,ABC family USA 
abc.com

#EXTINF:0,ABC HD USA
abc.com/usa

#EXTINF:0,AMC USA
amc.com/usa

#EXTINF:0,BLOMBERG USA 
 blomberg.com/usa

However I want the header and the link to be replaced to look like this:

#EXTINF:0,ABC family USA[]abc.com 

#EXTINF:0,ABC HD USA[]abc.com/usa

This way I could easily use this file and turn the contents into an array. However I don't want every new line to contain two brackets. I only want the header and link to be combined and have a bracket in between them. I am not sure how to accomplish this through notepad++ ?

Thanks for the help!

Upvotes: 0

Views: 41

Answers (1)

shender
shender

Reputation: 1283

If your text file is totally consistent (only contains lines like the original excerpt above, no trailing whitespace) you can use this regex to find line break characters occurring after and octothorpes:

\n(?!(^[#\s]))

and replace with:

[]

Results look like this:

#EXTINF:0,ABC family USA[]abc.com

#EXTINF:0,ABC HD USA[]abc.com/usa

#EXTINF:0,AMC USA[]amc.com/usa

#EXTINF:0,BLOMBERG USA[]blomberg.com/usa

Tested in Sublime Text 3 - Both ST and NP++ use Perl Regex, but there are slight variations so this might not work for you.

If it doesn't work in NP++, you can grab a copy of ST3 here.

Upvotes: 1

Related Questions