Search code examples
notepad++editing

Combine every 5 lines


I need to combine every 5 lines into 1. I have a wordlist dictionary which contains 1000 lines example:

line 1
line 2
.
line 1000

I need to combine every 5 lines:

line 1 line 2 line 3 line 4 line 5
.
line 996 line 997 line 998 line 999 line 1000

Solution

    • Ctrl+H
    • Find what: ^(.+)\R(.+)\R(.+)\R(.+)\R
    • Replace with: $1 $2 $3 $4
    • check Wrap around
    • check Regular expression
    • DO NOT CHECK . matches newline
    • Replace all

    Explanation:

    ^       : beginning of line
    (.+)    : group 1, 1 or more any character 
    \R      : any kind of line break
            : same pattern occurs 4 times.
    

    Replacement:

    $1      : content of group 1
            : a space
            : same for other groups