• Login
Community
  • Login

How can i concatenate every 7th line (5 groups of 7 long) to 1 line? Please help.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 250 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    John Goewie
    last edited by John Goewie May 11, 2024, 12:49 PM May 11, 2024, 12:33 PM

    Example :
    mklink /D "E:\Drum LIB\CLAP
    mklink /D "E:\Drum LIB\HIHAT
    mklink /D "E:\Drum LIB\KICK
    mklink /D "E:\Drum LIB\PERCUSSION
    mklink /D "E:\Drum LIB\CRASH
    mklink /D "E:\Drum LIB\SNARE
    mklink /D "E:\Drum LIB\STAB
    SAMPLECD1 - Techno - Clap
    SAMPLECD1 - Techno - Hihat
    SAMPLECD1 - Techno - Kick
    SAMPLECD1 - Techno - Perc
    SAMPLECD1 - Techno - Ride
    SAMPLECD1 - Techno - Snare
    " "
    " "
    " "
    " "
    " "
    " "
    " "
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
    H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
    "
    "
    "
    "
    "
    "
    "
    result concat:
    mklink /D “E:\Drum LIB\CLAP\SAMPLECD1 - Techno - Clap” “H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap”

    en repeat this for every 7 combinations. Tried with REGEX.

    C 1 Reply Last reply May 11, 2024, 4:29 PM Reply Quote 0
    • C
      Coises @John Goewie
      last edited by May 11, 2024, 4:29 PM

      @John-Goewie

      The best answer to this depends on a couple things:

      • Is this a “one shot” problem, or do you have to do this repeatedly (on many occasions, for many files, or both)?

      • Is your actual data consistent about having seven lines in every group, or do you have cases, as in your example, where some groups are short?

      If it’s a “one shot” problem, I’d use column selection. The handy “trick” is that if you select a column that includes line endings which are uneven and you paste or drag it before other data, the data to the right of the paste location will “snuggle up” to the end of the pasted data. So, in this example, first make a rectangular selection (click on the top left corner, then Alt+click on the last line far enough to the right to include all the data) enclosing the H:\SAMPLEBASE lines; then, drag that to left of the first of the " lines at the end.

      Now, enclose the " " lines and drag them before the lines you just created. Enclose and drag the SAMPLECD1 lines before those, add the missing \ characters (make a zero-width rectangular selection by clicking at the left of the first line, then Alt-clicking at the left of the last line; then just type the \ character), and finally, enclose and drag the mklink lines before those.

      That has the advantage of being able to see what you’re doing as you go, so you can make up for any oddities (like the uneven numbers of lines). However, it won’t help much if you have to do this for hundreds of files.

      If the data is actually regular (no missing lines, as in your example) and you have a lot of it to change, I’d start by joining sets of seven lines with tab characters; e.g.:

      Find what: ^(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)$
      Replace with: ${1}\t${8}\r\n${2}\t${9}\r\n${3}\t${10}\r\n${4}\t${11}\r\n${5}\t${12}\r\n${6}\t${13}\r\n${7}\t${14}

      You’ll need to Replace All repeatedly, until no more replacements are made; you’ll then have seven lines with tabs separating the lines that went together to make them. (You can do that for multiple files at once using the Find in Files tab.)

      Now you can use regular expressions to join the pieces together; for example,
      Find what: ^([^\r\n\t]*)\t
      Replace with: $1\\
      to join the first two parts with a \ between them.

      1 Reply Last reply Reply Quote 2
      • G
        guy038
        last edited by guy038 May 12, 2024, 9:14 AM May 11, 2024, 4:48 PM

        Hello, @john-goewie, @coises and All,

        Well, here is my first attempt, which mixes the regex capabilities, the column editor and the sort feature !


        First, I needed to add two lines in order to get a coherent set of lines. Hence, this text :

        mklink /D "E:\Drum LIB\CLAP
        mklink /D "E:\Drum LIB\HIHAT
        mklink /D "E:\Drum LIB\KICK
        mklink /D "E:\Drum LIB\PERCUSSION
        mklink /D "E:\Drum LIB\CRASH
        mklink /D "E:\Drum LIB\SNARE
        mklink /D "E:\Drum LIB\STAB
        SAMPLECD1 - Techno - Clap
        SAMPLECD1 - Techno - Hihat
        SAMPLECD1 - Techno - Kick
        SAMPLECD1 - Techno - Perc
        SAMPLECD1 - Techno - Ride
        SAMPLECD1 - Techno - Snare
        SAMPLECD1 - Techno - Stab
        " "
        " "
        " "
        " "
        " "
        " "
        " "
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
        H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab
        "
        "
        "
        "
        "
        "
        "
        

        The added lines are SAMPLECD1 - Techno - Stab and H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab

        • So, first, recopy the text above in a new tab

        • Put your caret ( cursor ) at the very beginning of the first line mklink ..... of your text

        • Then, with the following regex S/R, We add the letters A, B, C, D, E ,F ,G in front of each group of 7 lines :

        • SEARCH (?-s)^(.+\R)(.+\R)(.+\R)(.+\R)(.+\R)(.+\R)(.+\R)

        • REPLACE A$1B$2C$3D$4E$5F$6G$7

        => Your text becomes:

        Amklink /D "E:\Drum LIB\CLAP
        Bmklink /D "E:\Drum LIB\HIHAT
        Cmklink /D "E:\Drum LIB\KICK
        Dmklink /D "E:\Drum LIB\PERCUSSION
        Emklink /D "E:\Drum LIB\CRASH
        Fmklink /D "E:\Drum LIB\SNARE
        Gmklink /D "E:\Drum LIB\STAB
        ASAMPLECD1 - Techno - Clap
        BSAMPLECD1 - Techno - Hihat
        CSAMPLECD1 - Techno - Kick
        DSAMPLECD1 - Techno - Perc
        ESAMPLECD1 - Techno - Ride
        FSAMPLECD1 - Techno - Snare
        GSAMPLECD1 - Techno - Stab
        A" "
        B" "
        C" "
        D" "
        E" "
        F" "
        G" "
        AH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
        BH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
        CH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
        DH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
        EH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
        FH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
        GH:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab
        A"
        B"
        C"
        D"
        E"
        F"
        G"
        
        • Put the caret between the letter A and the text mklink of your first line

        • Open the column editor ( ALT + C )

        • Choose the Number to Insert option

        • Enter, successively, the numbers 1, 1 an 7, in the 3 zones

        • Check the Leading zeros option

        • Click on the OK button

        => You should get this text :

        A1mklink /D "E:\Drum LIB\CLAP
        B1mklink /D "E:\Drum LIB\HIHAT
        C1mklink /D "E:\Drum LIB\KICK
        D1mklink /D "E:\Drum LIB\PERCUSSION
        E1mklink /D "E:\Drum LIB\CRASH
        F1mklink /D "E:\Drum LIB\SNARE
        G1mklink /D "E:\Drum LIB\STAB
        A2SAMPLECD1 - Techno - Clap
        B2SAMPLECD1 - Techno - Hihat
        C2SAMPLECD1 - Techno - Kick
        D2SAMPLECD1 - Techno - Perc
        E2SAMPLECD1 - Techno - Ride
        F2SAMPLECD1 - Techno - Snare
        G2SAMPLECD1 - Techno - Stab
        A3" "
        B3" "
        C3" "
        D3" "
        E3" "
        F3" "
        G3" "
        A4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
        B4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
        C4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
        D4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
        E4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
        F4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
        G4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab
        A5"
        B5"
        C5"
        D5"
        E5"
        F5"
        G5"
        

        Now, still within the new tab, run the Edit > Line Operations > Sort Lines Lexicographically Ascending option

        => The text should be changed as below :

        A1mklink /D "E:\Drum LIB\CLAP
        A2SAMPLECD1 - Techno - Clap
        A3" "
        A4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
        A5"
        B1mklink /D "E:\Drum LIB\HIHAT
        B2SAMPLECD1 - Techno - Hihat
        B3" "
        B4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
        B5"
        C1mklink /D "E:\Drum LIB\KICK
        C2SAMPLECD1 - Techno - Kick
        C3" "
        C4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
        C5"
        D1mklink /D "E:\Drum LIB\PERCUSSION
        D2SAMPLECD1 - Techno - Perc
        D3" "
        D4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
        D5"
        E1mklink /D "E:\Drum LIB\CRASH
        E2SAMPLECD1 - Techno - Ride
        E3" "
        E4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
        E5"
        F1mklink /D "E:\Drum LIB\SNARE
        F2SAMPLECD1 - Techno - Snare
        F3" "
        F4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
        F5"
        G1mklink /D "E:\Drum LIB\STAB
        G2SAMPLECD1 - Techno - Stab
        G3" "
        G4H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab
        G5"
        

        Now, it quite obvious :

        • Use the following regex S/R

        • SEARCH (?-s)^.1(.+)\R..(.+)\R..(.+)\R..(.+)\R..(.+\R?)

        • REPLACE $1\\$2$3$4$5

        Here you are : you get your expected text !

        mklink /D "E:\Drum LIB\CLAP\SAMPLECD1 - Techno - Clap" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap"
        mklink /D "E:\Drum LIB\HIHAT\SAMPLECD1 - Techno - Hihat" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat"
        mklink /D "E:\Drum LIB\KICK\SAMPLECD1 - Techno - Kick" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick"
        mklink /D "E:\Drum LIB\PERCUSSION\SAMPLECD1 - Techno - Perc" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc"
        mklink /D "E:\Drum LIB\CRASH\SAMPLECD1 - Techno - Ride" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride"
        mklink /D "E:\Drum LIB\SNARE\SAMPLECD1 - Techno - Snare" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare"
        mklink /D "E:\Drum LIB\STAB\SAMPLECD1 - Techno - Stab" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab"
        

        Note :

        • In replacement, I added an antislash character which must be inserted between the first group and the second group !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 1
        • G
          guy038
          last edited by guy038 May 12, 2024, 9:51 AM May 12, 2024, 9:42 AM

          Hi, @john-goewie, @coises and All,

          @coises, I’ve analyzed your method and, really, your method is quicker and more efficient than mine ! However, for more than, let’s say, a dozen of lines to concatenate, I suppose that building the associate regexes would be tedious !

          BTW, I tried a variant of your method which works fine, too :

          In this variant, I prefered to not use the \t separator and included the EOL of groups 8 to 13 within the groups themselves !

          Thus, from this INPUT text :

          mklink /D "E:\Drum LIB\CLAP
          mklink /D "E:\Drum LIB\HIHAT
          mklink /D "E:\Drum LIB\KICK
          mklink /D "E:\Drum LIB\PERCUSSION
          mklink /D "E:\Drum LIB\CRASH
          mklink /D "E:\Drum LIB\SNARE
          mklink /D "E:\Drum LIB\STAB
          SAMPLECD1 - Techno - Clap
          SAMPLECD1 - Techno - Hihat
          SAMPLECD1 - Techno - Kick
          SAMPLECD1 - Techno - Perc
          SAMPLECD1 - Techno - Ride
          SAMPLECD1 - Techno - Snare
          SAMPLECD1 - Techno - Stab
          " "
          " "
          " "
          " "
          " "
          " "
          " "
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare
          H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab
          "
          "
          "
          "
          "
          "
          "
          

          The regex S/R is a bit simplified and becomes :

          • SEARCH (?-s)^(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*)\R(.*\R)(.*\R)(.*\R)(.*\R)(.*\R)(.*\R)(.*)

          • REPLACE $1$8$2$9$3$10$4$11$5$12$6$13$7$14

          and, after 3 clicks on the Replace All button, we get :

          mklink /D "E:\Drum LIB\CLAPSAMPLECD1 - Techno - Clap" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap"
          mklink /D "E:\Drum LIB\HIHATSAMPLECD1 - Techno - Hihat" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat"
          mklink /D "E:\Drum LIB\KICKSAMPLECD1 - Techno - Kick" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick"
          mklink /D "E:\Drum LIB\PERCUSSIONSAMPLECD1 - Techno - Perc" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc"
          mklink /D "E:\Drum LIB\CRASHSAMPLECD1 - Techno - Ride" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride"
          mklink /D "E:\Drum LIB\SNARESAMPLECD1 - Techno - Snare" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare"
          mklink /D "E:\Drum LIB\STABSAMPLECD1 - Techno - Stab" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab"
          

          Then, the simple S/R, below, adds the missing \ character, right before the first SAMPLECD1 string

          • SEARCH (?-i)[^\\](?=SAMPLECD1)

          • REPLACE $0\\

          Giving the expected OUTPUT text :

          mklink /D "E:\Drum LIB\CLAP\SAMPLECD1 - Techno - Clap" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Clap"
          mklink /D "E:\Drum LIB\HIHAT\SAMPLECD1 - Techno - Hihat" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Hihat"
          mklink /D "E:\Drum LIB\KICK\SAMPLECD1 - Techno - Kick" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Kick"
          mklink /D "E:\Drum LIB\PERCUSSION\SAMPLECD1 - Techno - Perc" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Perc"
          mklink /D "E:\Drum LIB\CRASH\SAMPLECD1 - Techno - Ride" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Ride"
          mklink /D "E:\Drum LIB\SNARE\SAMPLECD1 - Techno - Snare" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Snare"
          mklink /D "E:\Drum LIB\STAB\SAMPLECD1 - Techno - Stab" "H:\SAMPLEBASE\SAMPLECD1 - Techno\SAMPLECD1 - Techno - Stab"
          

          BR

          guy038

          1 Reply Last reply Reply Quote 0
          3 out of 4
          • First post
            3/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors