[CS-FSLUG] I need a quick way to edit quite a few html documents
davidm at hisfeet.net
davidm at hisfeet.net
Thu Jun 9 19:25:19 CDT 2011
"ls g*.htm?" does display a file list, but only of those files htm
files that end with an "l", so I guess that "?" means any letter that is
there, but insists that there be some letter there. escaping the period
didn't help, but that may be because I made too many changes before I
tried it.
Finaly: when I tried:"for file in i*.htm; do sed -i
's/index.html/index2.htm/g' $file; done" It worked for all the files
that started with "i" and ended with ".htm" Then: "for file in *.htm;
do sed -i 's/index.html/index2.htm/g' $file; done" Got the rest of them.
except for the ones that end with "l", or something completely
different.
Thanks this looks like an excellent tool if I can just learn how to use
it effectively.
Dave
On Thu, 9 Jun 2011 15:31:02 -0500, Robert Wohlfarth wrote:
> On Thu, Jun 9, 2011 at 2:58 PM, wrote:
>
>> for file in g*.htm?; do sed -i 's/index.php/index2.htm/g' $file;
>> done
>
>
>
>> 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.
More information about the Christiansource
mailing list