How to replace multiple lines of code?

16 replies
  • WEB DESIGN
  • |
Hi,

I have to replace the same HTML code of 8-10 lines across 200 pages.

Notepad++ only allows me a single line to be replaced.

Ideas, tips? :confused:
#code #lines #multiple #replace
  • Profile picture of the author peteJ
    Put the code in php, for example

    <?php
    // Put code here
    ?>

    save this as something like include.php

    Then, on each page you need it put

    require('include.php')

    Inside a php code block. This will call it at that place.
    {{ DiscussionBoard.errors[8401767].message }}
  • Profile picture of the author shipwrecked
    Can't... it's already there on all pages. It's an HTML code on about 200 pages and I don't want to go through all of those to modify it.

    They're should be some bulk replace possibility...
    {{ DiscussionBoard.errors[8401811].message }}
  • {{ DiscussionBoard.errors[8401825].message }}
  • Profile picture of the author David V
    There is an addon for Notepad++ which allows multi-line search and replace.
    See this StackOverflow thread.

    I prefer SublimeText2 personally, and you can do a multiple line search and replace.
    See the sublimetext2 docs.
    {{ DiscussionBoard.errors[8401826].message }}
    • Profile picture of the author Brandon Tanner
      +1 for Text Crawler. It's a great program, and will do what you want.

      But you are going about this the wrong way, and making it 1000 times harder than it has to be.

      Using PHP 'includes', as Pete mentioned, is the right way to do it, and will save you countless hours of frustration in the long run. Trust me on that. See this.
      Signature

      {{ DiscussionBoard.errors[8402564].message }}
      • Profile picture of the author shipwrecked
        Originally Posted by Brandon Tanner View Post

        +1 for Text Crawler. It's a great program, and will do what you want.

        But you are going about this the wrong way, and making it 1000 times harder than it has to be.

        Using PHP 'includes', as Pete mentioned, is the right way to do it, and will save you countless hours of frustration in the long run. Trust me on that. See this.
        I am using the "PHP include" on some pages.

        But this is an already built older .htm site that already doesn't have "PHP include" everywhere. I am trying to replace an already placed code that can be found across 200 pages.
        {{ DiscussionBoard.errors[8403418].message }}
        • Profile picture of the author Brandon Tanner
          Originally Posted by shipwrecked View Post

          I am using the "PHP include" on some pages.

          But this is an already built older .htm site that already doesn't have "PHP include" everywhere. I am trying to replace an already placed code that can be found across 200 pages.
          Right... what I meant was when you go in and change the code on all of those pages, you should put your 'include' calls on all of those pages, so that all future edits will be much easier.

          FYI... it is possible to run PHP code inside regular HTML files, by adding this to your .htaccess file...

          AddType application/x-httpd-php .html .htm

          ^ That will save you a lot of work if you already have a bunch of links pointing to your existing .html files. I just found out about that myself not too long ago... pretty cool trick.
          Signature

          {{ DiscussionBoard.errors[8404253].message }}
          • Profile picture of the author AskForeman
            Originally Posted by Brandon Tanner View Post

            Right... what I meant was when you go in and change the code on all of those pages, you should put your 'include' calls on all of those pages, so that all future edits will be much easier.

            FYI... it is possible to run PHP code inside regular HTML files, by adding this to your .htaccess file...

            AddType application/x-httpd-php .html .htm

            ^ That will save you a lot of work if you already have a bunch of links pointing to your existing .html files. I just found out about that myself not too long ago... pretty cool trick.
            I didnn't know you could change the htaccess file to compensate for the page not being a PHP extension, great tip.
            {{ DiscussionBoard.errors[8404933].message }}
    • Profile picture of the author shipwrecked
      Originally Posted by David V View Post

      There is an addon for Notepad++ which allows multi-line search and replace.
      See this StackOverflow thread.

      I prefer SublimeText2 personally, and you can do a multiple line search and replace.
      See the sublimetext2 docs.
      Thanks, I think it's going to work.

      The extension is a .dll file that I added to the Notepad++ plugin folder and a new menu has to be accessed (under PLUGINS) in order to use the tool.
      {{ DiscussionBoard.errors[8403362].message }}
  • Profile picture of the author David V
    I completely agree about using PHP includes, but you STILL have to make the initial change for the include on the 200 pages, and he did not say he needed to change it more then once, although it definitely should be done that way.
    But, outside the scope of the question, you should use php so changes you need to make to headers, footer, etc.... are super easy and fast.

    Note: If you do use a php include (which you should), you'll need to also change all your .html pages with includes to a .php extension.
    You'll also need to notify search engines (typically via htaccess) that the pages have changed. (from .html to .php) since they are not the same.
    {{ DiscussionBoard.errors[8402701].message }}
  • Profile picture of the author Jared Hale
    Dreamweaver, from MX to CS6 has power replace. You can select all files in a website, all selected files and individual files. It also allows you to enter block text, match by case and ignore white spaces.

    If you are on a Mac. Get a copy of BBEdit and check out AppleScript which is like Photoshops' Actions. With these use can record the BBEdit action of replacing what you need to do then use the applescript you created to do 100's of files.

    The other option I can suggest is to create a job on Getacoder.com, should cost you maybe $10 for someone to do it as it's a super simple job.

    Or if you want, PM me an example and if it will only take a few minutes, I will do it for you.
    Signature
    {{ DiscussionBoard.errors[8402814].message }}
  • Profile picture of the author yestyle
    Banned
    Using Dreamweaver is easy way to replay text that you want
    {{ DiscussionBoard.errors[8402907].message }}
    • Profile picture of the author Tlipre
      If I don't see this topic.
      now I still press ctrl+f and ctrl+v again and again.
      {{ DiscussionBoard.errors[8403002].message }}
  • Profile picture of the author BluthCompany
    If you still need an answer and for all those who like to know an easy way to do this

    • Download Sublime Text 2 (hands down the best editor)
    • Drag your project folder into the left, light grey, area of ST2 where it says "Open Files"
    • Right click the folder and click "Find in folder"
    • Fill the "find" input and the "Replace" input and click Replace
    • After you click OK to confirm a bunch of files are gonna open up, go to File -> Save All
    • Then File -> Close All Files
    • Dump Notepad++ and start using ST2, I used to use Notepad++ believe me ST2 is much better

    Good luck
    {{ DiscussionBoard.errors[8406253].message }}
  • Profile picture of the author AskForeman
    I have done this before quickly and easily just using the library feature in Dreamweaver, but the initial task is still time consuming whatever you use.
    {{ DiscussionBoard.errors[8407202].message }}
  • Profile picture of the author avajo71
    Had you ever tried using regular expression in notepad++?

    I usually use it when I need to place same code or texts to thousand of different lines.

    Google it if you haven't.
    {{ DiscussionBoard.errors[8626241].message }}

Trending Topics