gsxr1300
gsxr1300

Reputation: 413

Replace every n linebreak to tabs in a file

is it possible to replace every 4 Lines the Break to a Tab in UE or NPP with a regex search/replace?

File before:

    #12
    ab
    cde
    ef
    #34
    ghij
    ijk
    kl
    #5678
    uv
    w
    xyz
...

should be after replace

#12 ^t ab ^t cde ^t ef
#34 ^t ghij  ^t ijk ^t kl
#5678 ^t uv ^t w  ^t xyz

Upvotes: 3

Views: 1828

Answers (2)

Tensibai
Tensibai

Reputation: 15784

[\n\r](?!#) Will do and replace by \t

It will replace crlf if not followed by a # by tab when using windows encoding. (?!#) is a negative lookahead which exclude any \n or \r followed by a # (on next line)

Beware it will leave a space before the tabs, if you really wish only tab between each field you may have to change encoding to have only \n or \r (linux or mac).

Upvotes: 2

Toto
Toto

Reputation: 91508

Here is a way to do the job:

Find what: (.+)\R(.+)\R(.+)\R(.+\R)?
Replace with: $1\t$2\t$3\t$4

Check Regular Expression
DON'T check dot matches newline
and click Replace All.

Explanation:

(.+)\R   : Capture in group 1 everything until a line break (excluded)
(.+)\R   : Capture in group 2 everything until a line break (excluded)
(.+)\R   : Capture in group 3 everything until a line break (excluded)
(.+\R)?  : Capture in group 4 everything until a line break (included), optional

\R stands for any kind of linebreak (ie. \r or \n or \r\n)

Upvotes: 5

Related Questions