Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: [gentoo-user] [OT]batch processing html files

From: Etaoin Shrdlu <shrdlu(at)unlimitedmail.org>
Date: Wed Apr 30 2008 - 12:04:23 EDT


On Wednesday 30 April 2008, 17:52, Matthew R. Lee wrote:

> I have a folder full of .html files and I need to go through and
> replace in each and every one of them a couple of bits of info. I know
> I can do this using the following from the command line:
> sed 's/VV, ppp-ppp/81, 51-67/' file.html > newfile.html | mv
> newfile.html file.html
> Problem is I need to do this on nearly 200 files. I assume it could
> be done with a script, but I have zero experience in writing scripts.

If all the files are in the same directory, you can do

cd /your/directory
for f in *.html; do
  sed -i 's/VV, ppp-ppp/81, 51-67/' "$f" done

The -i flag tells sed to edit the file "in place", ie, the changes are made to the file itself (of course, sed does create a temporary file behind the scenes, but that is handled by sed). To stay on the safe side, I suggest specifying a suffix to -i, so that sed creates backup copies of the files, eg

sed -i BAK etc.

will create a backup file called "$f.BAK" when modifying "$f". When you're sure the changes are correct, you can of course delete all the BAK files. Otherwise, use them to restore the original files and start over.

Hope this helps.

-- 
gentoo-user@lists.gentoo.org mailing list
Received on Wed Apr 30 12:11:16 2008
Do you need help?X

This archive was generated by hypermail 2.1.8 : Sat Aug 02 2008 - 05:07:08 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library