Combine 2 files line by line



  • Re: Combine 2 texts line by line

    8dd6bb04-f07d-4b7b-93ac-9fbf88202782-imagen.png

    I just want to improve on a old answer, because i just need to mix 2 files line by line and the answer in an old post from 2017 help me a lot. On file1 go to Edit -> Column Editor and insert numbers, the key (and the improvement) is to start with a high number bigger than the number of lines, so if you have 352 lines just use something like 1000 o 10000 (if you have more than 500 lines) and increase by 2 (thats very important also). Then on file2 add numbers in the same way but start at 1001 or 10001 also increased by 2. In this way, you got odds and even on different files, then you copy and paste one into another, do a sort line, then select the numberts using column mode an delete them.



  • @Fernando-Sorensen

    Thanks for sharing your idea. That is a good addendum to that older post. Since that older topic wasn’t locked yet, I posted a link from there to here, so others who find that thread will be able to see your suggestion, too.



  • @PeterJones said in Combine 2 files line by line:

    That is a good addendum to that older post.

    As Peter said, that is a good addendum to THAT-OLDER-POST. :-)



  • Hello, @ fernando-sorensen, @peterjones and All,

    Indeed, very clever method, Fernando ;-))


    Now, assuming the input text, below, where I, deliberately, added some Tabulation or Space chars and sometimes none :

    1000	   		Line A in File 1
    1001	   		Line B in File 2
    1002Line C in File 1
    1003  Line D in File 2
    1004    Line E in File 1
    1005		Line F in File 2
    1006Line G in File 1
    1007	Line H in File 2
    1008 Line I in File 1
    1009	     Line J in File 2
    

    You may want to place the lines, of same number, in the same resulting line and delete the temporary leading numbers, in one go. If so, and assuming that your list begins with an even number, use the following regex S/R :

    SEARCH (?-s)^\d+[02468]\h*(.+)\R\d+\h*   OR   (?-s)^\d+[13579]\h*(.+)\R\d+\h* if the list begins with an odd number

    REPLACE \1\x20

    And you’ll get your expected output text :

    Line A in File 1 Line B in File 2
    Line C in File 1 Line D in File 2
    Line E in File 1 Line F in File 2
    Line G in File 1 Line H in File 2
    Line I in File 1 Line J in File 2
    

    The space separator character \x20, used in replacement may be changed to \t or \x20\x20\x20 or, even, \x20+\x20 !


    Of course, if you just would like to get rid of the temporary leadings blank chars, beginning each line, simply use :

    SEARCH ^\d+\h*

    REPLACE Leave EMPTY

    And, this time, you’re left with :

    Line A in File 1
    Line B in File 2
    Line C in File 1
    Line D in File 2
    Line E in File 1
    Line F in File 2
    Line G in File 1
    Line H in File 2
    Line I in File 1
    Line J in File 2
    

    Best Regards,

    guy038



  • @Alan-Kilborn said in Combine 2 files line by line:

    As Peter said, that is a good addendum to THAT-OLDER-POST. :-)

    Oopps, didn’t notice until now that the OP linked to that older post at the very beginning; sorry for the extraneous traffic.
    And now even more traffic, to point that out.
    :-(


Log in to reply