Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 704
gsxr1300 Avatar asked Nov 02 '25 19:11

gsxr1300


1 Answers

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)

like image 192
Toto Avatar answered Nov 05 '25 15:11

Toto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!