Notepad++ Merge 10+ lines into 1 line

1

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.

pau13z

Posted 2017-02-07T02:44:13.133

Reputation: 11

Have you tried TextFX Plugin in Notepad++, It provides a menu option TextFX>TextFX Edit>Unwrap Text which does what you require ? Also you could have just replaced \r\n with \t in extended search mode – AEonAX – 2017-02-07T04:08:00.677

Answers

3

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.

user686699

Posted 2017-02-07T02:44:13.133

Reputation: 1 703

Hi Gypsy, using option 1 I got:

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

And using option 2, I got:

g{a} g{b} g{c} g{d} g{e} g{f} g{g} g{h} g{i} g{j} g{k} g{l} g{m} – pau13z – 2017-02-08T20:17:22.967

Scrap that, using option 1 nothing happened

And using option 2, I got:

g{a} g{b} g{c} g{d} g{e} g{f} g{g} g{h} g{i} g{j} g{k} g{l} g{m} – pau13z – 2017-02-08T20:23:24.153

My bad. The \g{12} and \g{name} versions are for backreferences in the search itself. Here are the corrected versions: 1) Instead of \g{12} use ${12}. So it's ${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}. 2) Instead of \g{a} use $+{a}, so it's $+{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}. Notice that in both versions there is no \ before the $. For version 2 the search string stays the same. BTW the (?<a>... is not limited to 1 character. It can be (?<my_flag_15>..., for example. – user686699 – 2017-02-08T22:48:04.140

@pau13z. Answer updated with the corrected replacement strings. Sorry for that. – user686699 – 2017-02-09T03:16:13.937

Legend! Option 1 worked for me :) Cheers mate – pau13z – 2017-02-10T01:16:42.907

2

Method 1

Search → Replace...

  • Find what: \r\n
  • Replace with: \t
  • Wrap around: Checked
  • Search mode: Regular expression

Method 2

Edit → Blank Operations → EOL to Space

user477799

Posted 2017-02-07T02:44:13.133

Reputation:

0

If all set of 13 lines begin with Date/Time:, you could do this. It will replace all linebreaks that are not followed by Date/Time with a tabulation:

  • Ctrl+H
  • Find what: \R(?!Date/Time:)
  • Replace with: \t
  • UNcheck Match case
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

\R              : any kind of linebreak
(?!             : start negative lookahead, make sure we don't have after
  Date/Time:    : literally
)               : end lookahead

Result for 3 sets of lines:

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

Toto

Posted 2017-02-07T02:44:13.133

Reputation: 7 722