[Gllug] Batch Text Replacement

Dan Kolb gllug at eco.li
Mon Oct 29 13:11:08 UTC 2007


On Mon, Oct 29, 2007 at 12:34:19PM +0000, John Hearns wrote:
> On Mon, 2007-10-29 at 11:41 +0000, Dan Kolb wrote:
> > On Mon, Oct 29, 2007 at 08:50:33AM +0000, Tethys wrote:
> > > 
> > > 	for file in *.html
> > > 	do
> > > 		tmp=$(mktemp "$file.XXXXXXX")
> > > 		sed 's/ *style="[^"]*"//' "$file" > "tmp" && mv "$tmp" "$file"
> > > 	done
> > 
> > GNU sed allows for in-place editing, so you don't need the redirects and 'mv'.
> > Check up on the '-i' option.
> 
> Depends on how dangerously you want to live.
> 
> I use sed -i myself, when I have call to get sed out of the armoury.
> 
> But ALWAYS ALWAYS back up files before developing/testing sed scripts.

Surely that goes without saying! But if you don't want to live dangerously,
then there's an extra parameter to -i, which creates a backup file with a given
suffix.

Dan
-- 
It's lucky you're going so slowly, because
you're going in the wrong direction.
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list