search and replace throughout directories...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mousel
    Senior Member
    • May 2000
    • 281
    • 5.0.0

    search and replace throughout directories...

    Hi,

    I want to add a line of code to the top of every *.php page. I'm trying to write a script to do this but am having trouble because the files are not all in the same directory.

    For example:

    /users/directory1/index.php
    /users/directory1/subdirec/index2.php
    /users/directory2/index.php
    /users/directory2/subdirec/index.php

    Are there any existing scripts to do this with and if not could someone get me started in the right direction?

    Thanks in advance,

    Tim
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available
  • Mark Hensler
    Senior Member
    • Feb 2001
    • 570

    #2
    I don't know of any prefab script that do this. You could write a shell script to do this.

    How many files are we talking about? Can you just use an editor with a multi-file Search & Replace?

    Comment

    • Zzed
      Senior Member
      • Feb 2002
      • 133

      #3
      Would you settle for a unix shell script?

      I'll post it if you are interested.

      Comment

      • Tim Mousel
        Senior Member
        • May 2000
        • 281
        • 5.0.0

        #4
        Hi,

        I could use search and replace in homesite but I'd have to download hundreds of files.

        I would definitely settle for a shell script! That would be great.

        Thanks,

        Tim
        Five Star Review Script - Add reviews to your website!
        Mixed Martial Arts - Houston MMA Training
        Women's Self-Defense - Courses and DVDs available

        Comment

        • Zzed
          Senior Member
          • Feb 2002
          • 133

          #5
          Ok, how about a one liner?

          Try this in the parent directory: /users

          Code:
          for i in `find . -name "index*.php" -print`;do echo "<<< This is the text to add >>>" > /tmp/foo; cat $i >> /tmp/foo; cp /tmp/foo $i;done
          Note that the statement: find . -name "index*.php" -print is enlcosed in backticks: ` and not single quotes.

          This one liner will recursively look for all index*.php files and prepend it with the tect you want.

          Comment

          • Tim Mousel
            Senior Member
            • May 2000
            • 281
            • 5.0.0

            #6
            Hi,

            Great! Thank you so much. I'll give it a try.

            Tim
            Five Star Review Script - Add reviews to your website!
            Mixed Martial Arts - Houston MMA Training
            Women's Self-Defense - Courses and DVDs available

            Comment

            • Zzed
              Senior Member
              • Feb 2002
              • 133

              #7
              Let me know how it goes.

              Comment

              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
              Working...
              😀
              😂
              🥰
              😘
              🤢
              😎
              😞
              😡
              👍
              👎