Search code examples
notepad++

Join two lines into one line using notepad++


iam trying to creat csv file from .txt file and now iam stuck at this point

Sample text file

http://website1.com/imageartist.png,Artis Name,Pop Rock
https://website2/music/mymusicpop.mp3

https://website43.com/albumimages.png,Artis Name,K-Pop
http://website7/music/mymusickpop.mp3

https://website23.com/anotherimage.png,Artis Name,Heavy Metal
www.website5/music/mymusicmetal.mp3

www.website63.com/singerimage.png,Artis Name,Jazz
https.website5/music/mymusicjazz <-some lines have no .mp3 extension

i want like this

http://website1.com/imageartist.png,Artis Name,Pop Rock,https://website2/music/mymusicpop.mp3

https://website43.com/albumimages.png,Artis Name,K-Pop,http://website7/music/mymusickpop.mp3

https://website23.com/anotherimage.png,Artis Name,Heavy Metal,www.website5/music/mymusicmetal.mp3

www.website63.com/singerimage.png,Artis Name,Jazz,https.website5/music/mymusicjazz

how can i do this using notepad++?


Solution

  • This will join lines separated by a single linebreak.

    • Ctrl+H
    • Find what: ^.+\K\R(?!\R)
    • Replace with: ,
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    ^                   # beginning of line
      .+                # 1 or more any character but newline
      \K                # forget all we have seen until this position
      \R                # any kind of linebreak (i.e. \r, \n, \r\n)
      (?!\R)            # negative lookahead, make sure we haven't a linebreak after
    

    Screen capture (before):

    enter image description here

    Screen capture (after):

    enter image description here