D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] sed question



On 18 Jun 2003 at 12:52, trewornan wrote:

> How do I apply a substitution to a bunch of files [eg
> *.htm] and then save the results back under the same
> file names.
> 

I use perl.

Try

perl -pi -e's/whatever/youwant/g' *.html

Usage: perl [switches] [--] [programfile] [arguments]
  -e 'command'    one line of program (several -e's allowed, omit programfile)
  -i[extension]   edit <> files in place (makes backup if extension supplied)
  -p              assume loop like -n but print line also, like sed

I have added the g switch to the substitute so all occurrences on the line get 
changed, remove it if you only want the first to chage.

If you want to keep backups of the files processed then add .bak immediately after 
the i (no space) and it will copy the files with .bak added before processing.


Cheers,

Pete.
> The following works for one file at at time:
> 
> sed 's/whatever/youwant/' onefile.htm > onefile.html
> 
> but I've got lots of files and its going to take ages.
> 
> Anybody who can come up with a one liner?
> 
> Mark
> 
> ______________________________________________________________________
> __ Want to chat instantly with your online friends?  Get the FREE
> Yahoo! Messenger http://uk.messenger.yahoo.com/
> 
> --
> The Mailing List for the Devon & Cornwall LUG
> Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
> message body to unsubscribe.
> 



--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly