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.

  • 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 Feb 7 '17 at 4:08
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.

  • 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 Feb 8 '17 at 20:17
  • 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 Feb 8 '17 at 20:23
  • 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. – Gypsy Spellweaver Feb 8 '17 at 22:48
  • @pau13z. Answer updated with the corrected replacement strings. Sorry for that. – Gypsy Spellweaver Feb 9 '17 at 3:16
  • Legend! Option 1 worked for me :) Cheers mate – pau13z Feb 10 '17 at 1:16
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

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.