Community
    • Login

    Copy From one text file and Paste it on another Text File using Regex

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    25 Posts 4 Posters 3.4k 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.
    • Ohm DiosO
      Ohm Dios @guy038
      last edited by

      @guy038 .Functioning is absolutely Right. Only 100 paragraph copied and corresponding file_1 deleted. But after 100 , the file_2 content totally replaced by file_1. Instead of copied and deleted. May be the number issue because until 100 perfect after that only issue comes.
      I understood the function . lines ====== below will be copied to respective above after it gets deleted till the iteration of Paragraph Numbering.
      1-100 NO ISSUE. Issue starts from 101 then all the content of file_1 directly replaced till end of file_2.Hope i explained a little you may catch my point.

      1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R @Ohm Dios
        last edited by

        @Ohm-Dios said in Copy From one text file and Paste it on another Text File using Regex:

        Only one small Bug Found that after completion END tag creates another 4 empty Lines and one More END tag adds

        If you are finding there are unpaired END tags then I would assume they were there from the start. As a suggestion you can count the number of START and END tags in each file to confirm each file has the same number. To do so, use the Find function. Then type in (?-i)^START\s*\d+$ and click on the Count button. perform the same with (?-i)^END$. After getting that number you could then also perform another count as a secondary verification to count each set of START/END tags by using (?s-i)^START\s*\d+\R.+?^END$. If any of those numbers differed from the others you have an issue with your data.

        There is one other count I’d like you to do since I have thought of one possibility where the empty START/END line would appear after the replacement START/END line at step 4. Use (?-si)^START.+?\R[!"#$] on file 1 and confirm the number is 0. If it is NOT 0 then I may need to amend slightly my regexes

        As for my solution being a lengthy process, it is, intentionally. @guy038 solution is a much neater solution, however as he pointed out there can be issues using it on larger amounts of data. That’s why I refrain from offering it.

        You also posted a question about step 5 with 2 START tags. I don’t know if you completely understand each step, although I did provide a description for each step. In step 5 we have 2 START/END lines together. The first should be the “empty” START/END line, the second the replacement START/END line. As the first has the original “line number” attached at the end we need to keep that. Step 5 regex identifies the relevant strings of characters in both lines, keeps the replacement START/END string, but attaches the number from the first line.

        Terry

        1 Reply Last reply Reply Quote 1
        • guy038G
          guy038
          last edited by guy038

          Hello, @ohm-dios,

          If your File_1 and File_2 files are not personal nor confidential, could you send me these files, by e-mail, for further testing sequences ?

          My e-mail address, temporary displayed :

          BR

          guy038

          Ohm DiosO 1 Reply Last reply Reply Quote 0
          • Ohm DiosO
            Ohm Dios @guy038
            last edited by

            @guy038 Dear sir, Files are not personal. But i found the issue as i told after 100, then i checked START 101 it has START 101 . (FULL STOP) That only caused the issue. After clear the character it worked without any issue. It’s god’s grace that’s why i have got help from like you masters to save my efforts and time . My Love and Hug to You. Thanks You Rock always.

            1 Reply Last reply Reply Quote 1
            • guy038G
              guy038
              last edited by

              Hi, @ohm-dios,

              Ah…, of course ! In the search regex :

              (?s-i)START\h*(\d+).+?END\R(?=.+(START\h*\1\R.+?END\R?))|^===.+

              You’ll notice the part START\h*\1\R, which defines the beginning of the paragraph that need to be copied, located under the ======== line

              The back-reference \1 to the group 1 ( which is the number after the START string and space char(s) ) must be immediately followed with the EOL chars ( \R )

              Thus, if anything is located between the number and the end of line, it cannot be equal to the corresponding number, located above the ========= line => NO match of this specific paragraph :-((

              BR

              guy038

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors