Find the answer to your Linux question:
Results 1 to 4 of 4
I need to find and replace names in a big script including subfolders. Does a command exist to do that in batch even in the subfolders ? Or even better ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    22

    Find replace tool or command


    I need to find and replace names in a big script including subfolders.
    Does a command exist to do that in batch even in the subfolders ? Or even better a graphic application?
    Any suggestion is welcome
    Padu

  2. #2
    Linux Newbie x1a4's Avatar
    Join Date
    Dec 2006
    Posts
    123
    Use your text editor's Replace functionality or the tcsh script below. Unfortunately the script only replaces text in one file, so you have to run it for each file you want to change (or modify the script). To run the script execute: script /path/to/file OLD-TEXT NEW-TEXT

    Code:
    #!/usr/bin/tcsh
    
    set infile=$argv[1]
    set old=$argv[2]
    set new=$argv[3]
    set tmpfile=/tmp/fr
    
    sed 's/$old/$new /g' $infile > $tmpfile
    mv -f $tmpfile $infile
    
    unset {infile,tmpfile,old,new}
    EDIT: I don't remember if sed is installed by default so you might have to install it first if it's not. Same for tcsh

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    22
    Thanks for your quick reply...
    But I can come to this result using the text editor...
    I really need a solution for batch even in the subfolders... In webdesigning and programming we use this function quite often. I have a small program running under windoz doing that... Homesite and Dreamwaver has it integrated.
    For example today I need to find replace a file name on a script with more than 600 files... with the help of a script I will do it in a few minutes, manualy I will not be able to finish it today... and tomorrow search for a new job if I am so slow in my task
    Padu

  4. #4
    Just Joined!
    Join Date
    Mar 2008
    Posts
    1
    Hi,
    I was in the same boat with the need to replace a bunch of text in web pages. I used regexxer.
    regexxer Search Tool

    It worked like a charm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •