Community
    • Login

    Page break Text File saving

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    page break
    25 Posts 5 Posters 2.6k 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
      last edited by

      1)Text file has page breaks FF.
      2)How to save in multiple text file based on FF or to pdf format.

      NOTE: When converting text to pdf using adobe acrobat and pdf xchange (FF)no response. Its just converting as normal text to pdf .

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Ohm Dios
        last edited by

        @Ohm-Dios

        Not sure what the question is here.
        If it is how to save as PDF format then it is off-topic as Notepad++ does not do this.

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

          @Ohm-Dios said in Page break Text File saving:

          How to save in multiple text file based on FF

          A regex (regular expression) could be used with the “Find” function to capture from the start of the file to the first FF string. Then you would cut that, open a new tab, insert the captured area and save.
          A possible regex would be similar to
          (?s)(.+?)( FF)
          Things to consider.

          1. The new tab (with the cut lines) could be saved and then the process repeated if a macro was used. However once the new tab is closed and another opened it has the same name as previous one. To get around that using say the first (up to) 8 characters of each captured string can be used as the filename. That should be unique enough. The time stamp on each saved file allows them to be sorted into the correct order. Alternatively an ascending number against the margin of each line, then for the line with the special “page break” characters, this could be used as the filename, all other numbers would be removed prior to the cutting procedure.
          2. how to deal with normal line breaks (normally carriage return and line feed), are these following the page break string?
          3. The last section, as there isn’t a last “page break” at end of file, this needs to be catered for. Possibly as the macro ceases this can be a last manual process.

          You will see I have given you 1 possible regex, but only other ideas as you haven’t provided much in the way of detail. Consider the questions above and if you want further help come back with answers to those questions and possible someone (maybe me) can help you further.

          As for PDF format, if using a “virtual PDF driver” it’s possible to create PDF files (by printing to this driver), but not sure if this can be achieved using a macro within Notepad++, maybe someone else knows the answer to this question.

          Terry

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

            Thanks. I need to save the files automatically based on page break. For example my text file contains 1000 lines and approximately every 100 th line has FF. so i need to save 10 or 9 individual text files based on this FF(like starts after FF and ends before FF) automatically. Naming as you mentioned taking 8 letters after FF is good enough. PDF conversion asked for the same purpose only. If pdf is offtopic no problem. My aim is to save single text file to Multiple text file based on normal page break FF.
            If Macro is the only option then please Explain little bit in detail.

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Terry RT
              Terry R
              last edited by

              @Ohm-Dios said in Page break Text File saving:

              For example my text file contains 1000 lines and approximately every 100 th line has FF. so i need to save 10 or 9 individual text files based on this FF

              A macro is just the sequence of keyboard commands saved so it can be run over and over again. As you refer to a single file with perhaps 10 page breaks creating macros is possibly unnecessary. If however you need to perform the same steps over and over again on lots of files over a period of time then macros are the way to go.
              I’ve been doing some tests and it appears it’s not possible to name each file containing 1 section of the big file based on text within the file, at least when using the macro method. I have a method to get around this, which will work when recorded as a macro.
              The work I have done is on my work PC which means a wait of about 14hrs before I can provide it.
              If however you want something to try earlier I’ll see if I can provide it now.

              1. Use the Find function with the regex (Regular expression)
                Find What:(?s)\A(.+? FF)
                Search mode must be regular expression. Click on the “Find Next” button. It will highlight from the start of the file until the first page break.
              2. You can close the Find Window, then select “Cut” from the Edit menu.
              3. From the File menu, select New which creates a new Tab. You can then “Paste” which is under the Edit menu.
              4. If you want to remove the page break then use the “Replace” function and use
                Find What: FF
                Replace With: leave this field empty. Search mode must be regular expression and click on Replace, or replace all. As there is only 1 in this section the result is that it is removed.
              5. Now you can save the tab as a real file. So if doing this manually you can name this file as you save. Then close this file and you will be back at the “big” file.

              Now you just need to repeat steps 1 - 5 for the 10 or so page break sections.

              So tomorrow I can read any replies you post and we can take it from there, either going the way of macros or what ever else you might need help with.

              Terry

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @Ohm Dios
                last edited by

                @Ohm-Dios

                I would say a scripting plugin and writing some code is the way to go with this, especially if you have a lot of files or this is more than a one-time need. Please advise on this, and if desired, we can get you started on this kind of path.

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

                  Yes, Few big files each file has approximately 400 pages means, 400 individual text file to be saved. As mentioned previous post Macro works but i have to do for each and every single page (macro takes the job of finding,cutting,putting it to new file for saving i have to enter the file name). When its selected for end of line to repeat it just takes first page and also if i enter the no of times manually , that too takes only first page and copies the same.

                  Alan KilbornA Terry RT 2 Replies Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Ohm Dios
                    last edited by

                    @Ohm-Dios

                    It appears that it has been done before.
                    The script HERE demonstrates how to split a file based upon an original file’s empty lines.
                    If you can see how the script works, you should be able to create your specific line_delim_regex for your situation.
                    Let us know what additional help you need – I anticipate some. :-)

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

                      Hello, @ohm-dios, @terry-r, @alan-kilborn and All,

                      An easy way to get to split a file into multiples ones , according to some conditions, is to use the gawk software.

                      • First dowload the .exe from     https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/gnu-on-windows/gawk-4.1.0-bin.zip

                      • Create a gawk folder on your desktop

                      • Extract gawk.exe in this folder ( 223,246 bytes only )

                      • Move your file to split in this folder, too

                      • Open a DOS command-line windows

                      • Move to the new gawk folder wiht a cd command

                      • Type the command gawk "BEGIN { n=1 } !/\x0C/ { f = \"File_\"n\".txt\" ; print > f } /\x0C/ { n++ }" Your_File.txt

                      • Valid with the Enter key

                      => After several seconds, you should get as many files, named File_1.txt,File_2.txt,File_3.txt, .... in folder Gawk, as the number of FF characters ( \x0C ) in the file Your_File.txt

                      Note that this action does not change your initial file !

                      Of course, change the name Your_File.txt to the real name of your file which must be splitted

                      Best Regards

                      guy038

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn @guy038
                        last edited by

                        @guy038

                        Grumble grumble…solutions outside N++/plugins, before inside solutions are deemed “insufficient”. Grumble grumble… :-)

                        Another thing just occurred to me: Does OP expect FF to be at the end of each of the newly-created files, or are they purely delimiters that don’t appear? Since “formfeed” is in it, my guess would be that FF needs to be retained.

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

                          Hello, @ohm-dios, @terry-r, @alan-kilborn and All,

                          Alan, I hesitated to provide that solution because I knew you’d be annoyed because it’s outside N++ /plugins ;-))

                          Like a little boy, I say: I promise, Mom, I won’t do it again !

                          However, I’ve just found a much more quicker method :

                          gawk "BEGIN { n=1 ; f = \"File_1.txt\" } !/\x0C/ { print > f } /\x0C/ { n++ ; f = \"File_\"n\".txt\" }" Your_File.txt


                          And, as @alan-kilborn said, @ohm-dios, if you need to keep the FF character at the end of each created file, run that command, instead :

                          gawk "BEGIN { n=1 ; f = \"File_1.txt\" } !/\x0C/ { print > f } /\x0C/ { print > f ; n++ ; f = \"File_\"n\".txt\" }" Your_File.txt

                          Cheers,

                          guy038

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

                            @guy038
                            Hi I bow my head for your helping mind . It works like a charm. I love you so much. Thanks again to guy 038.
                            Thanks to Alan Kilborn for Pointing out FF. and Terry R for Macro guidance and Notepad++ community.

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

                              @Ohm-Dios said in Page break Text File saving:

                              As mentioned previous post Macro works but i have to do for each and every single page (macro takes the job of finding,cutting,putting it to new file for saving i have to enter the file name). When its selected for end of line to repeat it just takes first page and also if i enter the no of times manually , that too takes only first page and copies the same.

                              It’s good that you have a solution that works for you. I didn’t explain myself very clearly obviously as per your statement above.

                              If going with my macro idea you would not have needed to name each file created. I just mentioned that as you stated you had 1 medium sized file with perhaps 10 or so sections and the solution I then proposed would have been a manual one, no macros involved.

                              However with the addition of the statement “400 pages from a few big files” the macro idea would have made it easier. Most of the time we provide solutions for a “one off” issue or at most needed for a few small number of instances. Macro’s only come into play when the process needs repeating lots of time as it does involve some extra steps which are often considered too much extra work.

                              My steps were to be:

                              1. First macro creates the appropriate number of empty tabs, Notepad++ will create the tabs called “new 1”, “new 2”, “new 3” and so on.
                              2. Second macro cuts the first portion from the large file and inserts it into the “new 1” file, then saves and closes. The name of each file here would have been the “new 1”, “new 2” etc.
                              3. Macro then goes back to the original file (which is now shorter by the first section being removed). It then repeats step #2, so at this point the first section in the file is actually the 2nd of the original file.

                              There were still some testing to be done, but I had it fairly close to being a solution, and yes it was looking like being an automatic solution. The main work would have taken place at the start to get the macro’s recorded and initial setup.

                              Terry

                              Alan KilbornA 1 Reply Last reply Reply Quote 2
                              • Alan KilbornA
                                Alan Kilborn @Terry R
                                last edited by

                                @Terry-R

                                It seems the macro solution had some interesting aspects.
                                Maybe you want to carry it through and publish the workings?
                                If it seems to you a pointless effort at this point, because the OP has a solution, then it’s OK, don’t feel obligated. :-)

                                1 Reply Last reply Reply Quote 1
                                • Terry RT
                                  Terry R
                                  last edited by

                                  @Alan-Kilborn said in Page break Text File saving:

                                  @Terry-R
                                  It seems the macro solution had some interesting aspects.

                                  I wouldn’t necessarily say interesting, actually all the steps were fairly simple. However I’ve hit a snag, and it’s a big one.

                                  When I create the multiple “new #” files (step 1), these files ONLY exist within the NPP environment, they aren’t actual files on disk. So when I use the step to save them, the filename is pre-populated with the tab name (good so far), but the macro does not proceed past this point, instead stopping when the Save As dialog is open, it has to be “Save As” due to file not currently on disk, 1st time to save. So my “automatic” process has broken down.

                                  I recall another solution I had where I did a similar thing, appending the filename (as the tab header shows) as text on the last line to each file loaded. But those files already existed on disk, so the save and close functions worked without any user interaction.

                                  I’ve been searching this forum for articles where mention has been made about editing the macro manually and inserting codes corresponding to button presses or commands, where they will work but aren’t record-able through the normal process, @PeterJones this is where you join in, because you seem to have a very good handle on how to find these codes. I installed NppUISpy plugin, but that doesn’t help here.

                                  So either I need to pre-save these “new #” files before commencing the cut and paste operation or be able to have the macro proceed past the Save As dialog box with the default name in situ.

                                  Any ideas anyone?

                                  Terry

                                  Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
                                  • Alan KilbornA
                                    Alan Kilborn @Terry R
                                    last edited by

                                    @Terry-R said in Page break Text File saving:

                                    I wouldn’t necessarily say interesting… However I’ve hit a snag…

                                    Yep, it is a snag I anticipated from the earlier description.
                                    I thought you had found a solution to it, based on your earlier posting describing the algorithm.
                                    THAT is what I thought could be interesting. :-)

                                    Macros sometimes just don’t seem to go “far enough”.
                                    Perhaps that’s why I’m a rather avid scripter.

                                    I’ve often started something as a macro, then hit the “how to save-as the file” problem.
                                    It might be nice if the sParam on the SaveAs action could be used somehow to:

                                    • specify a hard filename, or perhaps:
                                    • specify a suffix for the active file, to use when saving the new file (example: an active file of c:\test\test2.txt becomes c:\test\test2_mysuffix.txt
                                    • if sParam is empty, e.g. sParam="" then current behavior (open SaveAs and put current file info into the setup of the dialog) is maintained
                                    • DISCLAIMER: don’t know that I’ve fully thought this all through :-)
                                    1 Reply Last reply Reply Quote 0
                                    • PeterJonesP
                                      PeterJones @Terry R
                                      last edited by PeterJones

                                      @Terry-R said in Page break Text File saving:

                                      I’ve been searching this forum for articles where mention has been made about editing the macro manually and inserting codes corresponding to button presses or commands, where they will work but aren’t record-able through the normal process, @PeterJones this is where you join in, because you seem to have a very good handle on how to find these codes. I installed NppUISpy plugin, but that doesn’t help here.

                                      Well, with the Save As (41008, from NppUISpy), it is not recordable, but it is playable. Last August, I shared a macro that did a New, then changed the file-type, then ran Save As, then edited and saved again, proving that you can move beyond Save As. Editing it for creating three new files and three save-as (and commenting using on Alan’s 2172 trick so that comments don’t get lost):

                                              <Macro name="CreateThreeSaveAsEach" Ctrl="no" Alt="no" Shift="no" Key="0">
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" />
                                                  <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" />
                                                  <Action type="2" message="0" wParam="41008" lParam="0" sParam="" />
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" />
                                                  <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" />
                                                  <Action type="2" message="0" wParam="41008" lParam="0" sParam="" />
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41001 = File|New" />
                                                  <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />
                                                  <Action type="0" message="2172" wParam="0" lParam="0" sParam="COMMENT: 41008 = Save|As" />
                                                  <Action type="2" message="0" wParam="41008" lParam="0" sParam="" />
                                              </Macro>
                                      

                                      This creates a file, runs Save As, waits for me to enter the name in the dialog manually, and does the same thing twice more, for a total of three files.

                                      No, I do not know of a way to pass a name to the Save As command – and using the type2 “menu command” style of command, it’s not going to be possible, because menu commands are, by definition, a single-click action; they are not set up to receive arguments directly.

                                      However, I just had an idea. Let me go run some experiments, and I’ll hopefully be back with another post soon, if it pans out.

                                      PeterJonesP 1 Reply Last reply Reply Quote 2
                                      • PeterJonesP
                                        PeterJones @PeterJones
                                        last edited by

                                        @PeterJones said in Page break Text File saving:

                                        However, I just had an idea. Let me go run some experiments

                                        I was hoping to use the Notepad++ message NPPM_SAVECURRENTFILEAS, which has a string lParam internally… but the type=0/1 macro commands only send messages to the current Scintilla window, not to the parent Notepad++ window; and the type=2 macro commands only send menu command IDs, not generic messages.

                                        So, from a macro, I still don’t know any way to specify the Save As name. As with Alan, I think this task is better suited to a scripting plugin than a macro.

                                        1 Reply Last reply Reply Quote 2
                                        • Terry RT
                                          Terry R
                                          last edited by

                                          @PeterJones said in Page break Text File saving:

                                          So, from a macro, I still don’t know any way to specify the Save As name.

                                          Thanks for the research. In your post there was a glimmer of hope in that I have the filename already populated. That comes from the tab name “new 1” etc. So I changed the 41006 to 41008 to see if it made a difference, nope!

                                          What’s interesting is that when I recorded the macro I used the “Save” function (41006, and this was in the macro). However what comes up is the “Save As” because obviously the file has never been created on disk.

                                          I thought it would be a long shot as your post referred to be unable to supply a filename, but surely every tab content that you try to save should have a “tab name” which should become the “filename” by default. So wouldn’t the filename field in the Save/Save As dialog box be filled with the default?

                                          So it’s a bust then. Oh well it was an interesting exercise anyways although not terribly complicated. I only attempted this due to my previous foray into macro’s saving a filename (as text) in the file content, updating and closing it which DID work. I thought I was onto a winner!

                                          Cheers
                                          Terry

                                          PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
                                          • PeterJonesP
                                            PeterJones @Terry R
                                            last edited by

                                            @Terry-R said in Page break Text File saving:

                                            I only attempted this due to my previous foray into macro’s saving a filename (as text) in the file content, updating and closing it which DID work

                                            Do you still have that macro? Because I don’t see how you could do that, either.

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