Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: find and replace a string

    I currently have a shell script (findreplace.ksh) that finds a word and replaces it with another word for all files in the specified directory
    #findreplace.ksh :
    perl -e "s/${1}/${2}/g;" -pi $(find ${3}/ksh -type f)

    Hence I would run the script as :
    findreplace dummy nodummy temp

    This would replace all occurances of dummy to nodummy in the temp/ksh folder.

    Now how do I do the following :
    If my arguments ${1} and ${2} have spaces in them, what option can I give to make it work ?
    For example, I need to replace the word <I am a Dummy> with <Not anymore a dummy" in the same fashion ?
    Also, I am interested in knowing if there are any other options to doing a find and replace(besides the perl command)
    Thanks

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Code:
    findreplace 'I am a Dummy' 'Not anymore a dummy' temp
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Type on the command line:
    Code:
    $ for i in "`ls *"I am a dummy"*`"
    > do                                
    > mv "$i" "`echo "$i" | sed 's/I am a dummy/Not anymore a dummy/'`"                               
    > done
    This is done in Linux so maybe the quoting thing works a little different in other UNIX systems. Spaces in filenames is not what UNIX is made for anyway...

    Regards
    Last edited by Tyveleyn; 09-15-07 at 06:51.

Posting Permissions

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