• Login
Community
  • Login

Adding multiple lines to the bottom of documents

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 2 Posters 1.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.
  • D
    David Smith179
    last edited by May 19, 2019, 2:58 PM

    Hi All,

    I have been left ‘in the lurch’ by a wayward developer who was updating a site of mine. I have nearly got things straight and working but have a problem on one batch of over 5000 html/php files. I have multiple lines to move in every one. I know how to select multiple lines in multiple files and delete them but I cannot find out how to select a sinle line (in this case the bottom statement </body></html>) and replace this with multiple lines (including of course finishing with </body></html>).

    Can anyone help?

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 May 19, 2019, 5:41 PM May 19, 2019, 5:30 PM

      Hello, @david-smith179,

      Welcome to the N++ Community !

      So, assuming a bunch of html/php files, in a single directory :

      • Is the multi_lines area to add, right before the </body></html> at end of files, be always the same ?

      • Roughly, what would be the maximum size of your multi-lines area to insert ?

      If this area is not too large, I suppose that this could be simply achieve with a regex S/R !

      See you later,

      Best Regards,

      guy038

      1 Reply Last reply Reply Quote 2
      • D
        David Smith179
        last edited by May 19, 2019, 6:27 PM

        Hi Guy,

        I need to add 7 lines before the </body></html> statement. For reasons known only to him my wayward developer moved these lines to near the beginning of the files. The Fancybox script screws up if not at the bottom. An added complication is that </body></html> are currently on the end of a script line:
        <script src=“https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js ” integrity=“sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM” crossorigin=“anonymous”></script></body></html>
        Just in case it matters these are the 7 lines:
        <script src=“…/…/script/jquery-1.10.1.min.js”></script>
        <script type=“text/javascript” src=“…/…/script/jquery.fancybox.pack.js”></script>
        <script>
        $(document).ready(function() {
        $(‘.fancybox’).fancybox();
        });
        </script>

        Thanks for trying to help.
        David

        1 Reply Last reply Reply Quote 0
        • D
          David Smith179
          last edited by May 19, 2019, 6:57 PM

          Me again Guy,

          I should add that I am not a programmer. I can do basic (old school!) html.

          The files are in multiple sub-directories (1 in each) of one directory.

          1 Reply Last reply Reply Quote 0
          • G
            guy038
            last edited by May 19, 2019, 7:16 PM

            Hi, @david-smith179, and All,

            First, as you said :

            I know how to select multiple lines in multiple files and delete them

            I suppose that you’ve already get rid of this 7-lines bunch, near the beginning of all your files !

            Now, if I understand you correctly, you would like to insert the text below :

            <script src="…/…/script/jquery-1.10.1.min.js"></script>
            <script type="text/javascript" src="…/…/script/jquery.fancybox.pack.js"></script>
            <script>
            $(document).ready(function() {
            $('.fancybox').fancybox();
            });
            </script>
            

            between </script> and </body></html>, at the end of the line, below :

            <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script></body></html>
            

            in order to obtain :

            <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
            <script src="…/…/script/jquery-1.10.1.min.js"></script>
            <script type="text/javascript" src="…/…/script/jquery.fancybox.pack.js"></script>
            <script>
            $(document).ready(function() {
            $('.fancybox').fancybox();
            });
            </script>             #
            </body></html>        #  or </script></body></html>
            

            Remarks :

            • I noticed that you used the … character, in lines 1 and 2 of your 7-lines area, which supposes some hidden text ! Note that, in order that the future regex S/R works correctly, the total amount of these 7-lines bunch, which will be inserted in the replacement zone, after a slight modification, should not exceed 2000 characters !

            • Please, verify if the above code zones, with black background, seem correct !

            If so, the regex S/R is a question of minutes ;-))

            BR

            guy038

            1 Reply Last reply Reply Quote 2
            • D
              David Smith179
              last edited by May 19, 2019, 7:26 PM

              Hi Guy,

              Yes it looks correct.

              The …/…/ is the path back to the script directory:

              mbl\script
              mbl\alpha\directory with php file in it

              If for some reason it looks wrong to you, don’t worry, it works!

              Thanks
              David

              1 Reply Last reply Reply Quote 0
              • G
                guy038
                last edited by guy038 May 19, 2019, 9:02 PM May 19, 2019, 8:49 PM

                Hi, @david-smith179, and All,

                Perfect ! First, I would like to remind you that the Find what : and Replace with : zones, of the Replace dialog, can contain a maximum amount of 2046 characters ! But, unlike the Find what : zone, which may contains a multi-lines text, the Replace with : zone can only a single line, ( from 0 to 2046 characters ! )

                So we need to transform your 7-lines text to add into a single line, which, in addition, must escape some meta-characters with the \ character, in order to obtain a complete literal single line. To achieve this :

                • Paste your 7-lines area in a new N++ tab

                • Add a line-break, right before this bunch of lines, hitting the Enter key

                • In the same way, add a line-break, right after the 7th line

                • Open the Replace dialog ( Ctrl + H )

                • SEARCH ([{}()\\$?:])|\R

                • REPLACE (?1\\$1:\\r\\n)

                • Tick the Wrap around option

                • Select the Regular expression search mode

                • Click on the Replace All button

                => You should obtain the one-line text below ( Actually, not exactly because of the ... zones not described ! ) :

                \r\n<script src="…/…/script/jquery-1.10.1.min.js"></script>\r\n<script type="text/javascript" src="…/…/script/jquery.fancybox.pack.js"></script>\r\n<script>\r\n\$\(document\).ready\(function\(\) \{\r\n\$\('.fancybox'\).fancybox\(\);\r\n\}\);\r\n</script>\r\n
                

                Now, here is the main regex S/R :

                • Copy this one-line text, above, in the clipboard

                • Switch back to your HTML file

                • If necessary, re-open the Replace dialog

                • Paste this one-line text in the Replacement with : zone

                • In the Find what : zone, type in the simple regex (?=</body></html>)

                • Again, click on the Replace All button

                So, from your initial last line :

                <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script></body></html>
                

                You should get, as expected, the text :

                <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
                <script src="…/…/script/jquery-1.10.1.min.js"></script>
                <script type="text/javascript" src="…/…/script/jquery.fancybox.pack.js"></script>
                <script>
                $(document).ready(function() {
                $('.fancybox').fancybox();
                });
                </script>
                </body></html>
                

                Notes :

                • The search regex ( (?=</body></html>) ) is a look-ahead structure, i.e. a zero-length assertion, which looks for the location right before the text </body></html>

                • At this location, all the one-line text, previously inserted in the Replacement zone, is written and any part \r\n is changed into a true line-break, in order to reconstitute the multi-lines text !

                Remarks :

                • I strongly advice you to test this final regex S/R on a single or few HTML file(s), to begins with !

                • If everything seems OK, backup the folder containing the files to be modified ( One nevers knows ! )

                • And, of course, use, this time, the Find in Files dialog to perform the regex S/R on all your HTML files

                Hope this helps ;-))

                Cheers,

                guy038

                1 Reply Last reply Reply Quote 2
                • D
                  David Smith179
                  last edited by May 19, 2019, 9:17 PM

                  Hi Guy,

                  Thanks - that’s all double dutch to me!

                  However, I can usually work these things out.

                  I am tied up at present so will not be able to tell you whether I succeded or not until tomorrow.

                  Many Thanks

                  David

                  1 Reply Last reply Reply Quote 1
                  • D
                    David Smith179
                    last edited by May 20, 2019, 12:55 AM

                    Hi Guy,

                    I found time to have a go - and totally screwed it up! On a few test files only thank goodness. Second attempt worked perfectly. I have since applied the solution to all my php files and uploaded them and, yers they do work.
                    https://www.minibottlelibrary.com/mbl/index.html (straights area)

                    Again, MANY THANKS.

                    David

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