[CS-FSLUG] I need a quick way to edit quite a few html documents

Robert Wohlfarth rbwohlfarth at gmail.com
Thu Jun 9 15:31:02 CDT 2011


On Thu, Jun 9, 2011 at 2:58 PM, <davidm at hisfeet.net> wrote:

> for file in g*.htm?; do sed -i 's/index.php/index2.htm/g' $file; done
>
<snip>

> I didn't try it as root - didn't know if it was safe to do so.  What am I
> missing? Or how have I messed up the command?
>

Some things that I would try...
1. Does "ls g*.htm?" display a file list? This will tell you if the problem
is in the glob or the sed command.
2. In the sed expression, escape the period: s/index\.php/index2.htm/g.
Theoretically, the period matches any character. The original, un-escaped
pattern matches "index-php" or "indexAphp". In practice, it probably doesn't
matter and I'm just being paranoid.
3. Put quotation marks around $file: sed -i 's/index.php/index2.htm/g'
"$file". This protects files that might have spaces in their name.

-- 
Robert Wohlfarth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ofb.biz/pipermail/christiansource_ofb.biz/attachments/20110609/9de11abd/attachment.htm>


More information about the Christiansource mailing list