Notepad++ Merge 10+ lines into 1 line

join;mergenotepadregex

I'm trying to use Notepad++ to merge multiple lines into one. The problem I'm facing is when trying this code, I get this result:

Date/Time:
Sequence:
Event:
Category:
Priority:
Attention:
Alert:
Visibility:
Description:
Codes:
Type:
Location:
Logged by:

Find: (.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)\r\n(.+)

Replace with:
\1\t\2\t\3\t\4\t\5\t\6\t\7\t\8\t\9\t\10\t\11\t\12\t\13\t

Result:
Date/Time: Sequence: Event: Category: Priority: Attention: Alert: Visibility: Description: Date/Time:0 Date/Time:1 Date/Time:2 Date/Time:3

Can anyone assist with a easier or shorter way? I can't highlight the text and select to Join Lines. The document has thousands of these results and I'm trying to streamline. It's always a set of 13.

Best Answer

Option 1: Change your replace to use braced numbers:

Edit: Corrected replacement string

\g{1}\t\g{2}\t\g{3}\t\g{4}\t\g{5}\t\g{6}\t\g{7}\t\g{8}\t\g{9}\t\g{10}\t\g{11}\t\g{12}\t\g{13}\t

${1}\t${2}\t${3}\t${4}\t${5}\t${6}\t${7}\t${8}\t${9}\t${10}\t${11}\t${12}\t${13}

Option 2: Your match string to include named groups:

(?<a>.+)\r\n(?<b>.+)\r\n(?<c>.+)\r\n(?<d>.+)\r\n(?<e>.+)\r\n(?<f>.+)\r\n(?<g>.+)\r\n(?<h>.+)\r\n(?<i>.+)\r\n(?<j>.+)\r\n(?<k>.+)\r\n(?<l>.+)\r\n(?<m>.+)

AND, change the replace string to use those groups:

Edit: Corrected replacement string

\g{a}\t\g{b}\t\g{c}\t\g{d}\t\g{e}\t\g{f}\t\g{g}\t\g{h}\t\g{i}\t\g{j}\t\g{k}\t\g{l}\t\g{m}

$+{a}\t$+{b}\t$+{c}\t$+{d}\t$+{e}\t$+{f}\t$+{g}\t$+{h}\t$+{i}\t$+{j}\t$+{k}\t$+{l}\t$+{m}

Your choice, although option 1 is less work, option 2 can come in handy as well.

New Note: The names in option 2, <a> and {a} are not limited to one character. They can be any 'name' type string you want, as long as it is in the normal range of letters, number, and underscores. Not sure if other special characters, including spaces, are valid. Avoiding them is wisest, just in case.

Related Question