Trouble With Editing Script For Multiple Files - Shell Scripting

This is a discussion on Trouble With Editing Script For Multiple Files - Shell Scripting ; Hey everybody, I have a script for making a string substitution in a file. I am trying to modify it in order to make the same modifcation to multiple files. here is what I have so far. #!/bin/csh set p1="$1" ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Trouble With Editing Script For Multiple Files

  1. Trouble With Editing Script For Multiple Files

    Hey everybody, I have a script for making a string substitution in a file. I am trying to modify it in order to make the same modifcation to multiple files. here is what I have so far.

    #!/bin/csh
    set p1="$1"
    shift
    set p2="$1"
    shift
    foreach x ($*)
    if ( { grep -w -c "$p1" $x } ) then
    mv $x $x.bak
    sed "s/$p1/$p2/g" $x.bak > $x
    else
    endif
    end

    An example of using the script would be
    ~/Unix/script/subst "hi guys" "hello everyone" myFile1.txt myFile2.txt

    which would make the same substitution in each file, and this should work for any number of files, with any substitution. the script works just fine for one file but I am haiving touble making it work for more than one currently.
    any help would be great. Thanks in advance!

  2. Re: Trouble With Editing Script For Multiple Files

    I dont have any idea regarding it when i need to know some thing i just go to Googles and search for it so know what would i do about it.

+ Reply to Thread