On Sat, Dec 15, 2007 at 09:45:50AM -0600, Mike Hammett wrote:
> Would the following command remove ../../Templates/ from all files in
> the /home/devicsil/public_html/Templates directory?
>
>
>
> for file in ls /home/devicsil/public_html/Templates
> ; do sed -e 's/..\/..\/Templates\///g' "$file" echo
> ---------------------------------------------------------------- done

That will remove all instances of
somecharactersomecharacter/somecharactersomecharacter/Templates/ from
those files.  Your sed command as written will only output the changes
to stdout, which is great for debugging before you actually change the
files.  You also need to use backticks around the ls command so that it
will be run in a subshell and it's output used in the for loop rather
than looping on "ls" and "/home/devicsil/public_html/Templates".

If your sed supports the inplace argument, as in FreeBSD's sed, you can
specify something like:

sed -i.bak -e 's|\.\./\.\./Templates/||g' "$file"

I think that will do what you intend to do by only changing
instances of "../../Templates/" instead of, possibly,
"somedirectoryname/aa/Templates/", if such names are a possibility in
the source files.  Your original regex would have matched the later
string and removed "me/aa/Templates/".

If your sed does not support the inplace argument, you will need to do 
something like:

for file in `ls /home/devicsil/public_html/Templates` ; do
   mv "$file" "$file.bak";
   sed -e 's|\.\./\.\./Templates/||g' "$file.bak" > "$file";
   echo "----------------------------------------------------------------":
done;

I haven't run that so it may have bugs.  Test first and, as always, have
a backup.

HTH,

-- 
Scott Lambert                    KC5MLE                       Unix SysAdmin
[EMAIL PROTECTED]



--------------------------------------------------------------------------------
WISPA Wants You! Join today!
http://signup.wispa.org/
--------------------------------------------------------------------------------
 
WISPA Wireless List: [email protected]

Subscribe/Unsubscribe:
http://lists.wispa.org/mailman/listinfo/wireless

Archives: http://lists.wispa.org/pipermail/wireless/

Reply via email to