Re: Multible search and replace?
When Joey Hess wrote, I replied: This is especially nifty because from may be a perl regular expression (including parentheses pairs enclosing substrings of itself) and to may include $1, $2... refernces to such pairs- very handy. Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Well, this is so easy to do in perl that I just write little programs to do it on the fly most of the time. Here's a little program that may do what you want: #!/usr/bin/perl -i.bak $find=shift; $replace=shift; while () { s/$find/$replace/g; print } Name it replace and call it like so: replace from to file [file ...] It can operate on multiple files, 'from' is the string you want to find, and it is replaced globally with 'to' in all the files. Backups are saved with a .bak extention. -- #!/bin/perl -sp0777iX+d*lMLa^*lN%0]dsXx++lMlN/dsM0j]dsj # RSA-3-lines-perl $/=unpack('H*',$_);$_=`echo 16dio\U$kSK$/SM$n\EsN0p[lN*1 # Joey Hess lK[d2%Sa2/d0$^Ixp|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) # [EMAIL PROTECTED] He. He. He. - - Herman Toothrot -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
This is especially nifty because from may be a perl regular expression (including parentheses pairs enclosing substrings of itself) and to may include $1, $2... refernces to such pairs- very handy. Well, not with the example I gave you can't, but if you use something like this, you can use all those wonderful perl regexp tricks: #!/usr/bin/perl -i.bak $find=shift; $replace=shift; while () { eval s/$find/$replace/g; print } -- true - do nothing, successfully - - true (1) -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
Chad Zimmerman wrote: Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Are you an Emacs user? Emacs has dired-do-query-replace, which is on the Operate drop-down mouse menu in dired-mode. You'd have to execute it once for each change to me made, but at least it would do all the files each time. -- ...RickM... -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
Chad Zimmerman ([EMAIL PROTECTED]) wrote: : Was just wondering if there is a package out that does multiple file : search and replaces? I have to go through my main html directory and make : a lot of repetive changes. Was wondering if there was a package or a perl : script laying arround to do this. Would same me the time of writing one : up. I think you should be able to do that with sed : sed s/X/Y filename replaces all Xs with Ys in the file 'filename'. I dunno if it takes * as an argument, but if it doesn't you should still be able to do it using xargs. Mat -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
-BEGIN PGP SIGNED MESSAGE- On Wed, 8 Jan 1997, Chad Zimmerman wrote: Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Yes, I wrote me such a perl script some time a go. I havent made a debian package of it though, but I'll send you the script. I somebody else is intrested, mail me... - -- Name: Hakan Ardo E-Mail: [EMAIL PROTECTED] WWW:http://www.ub2.lu.se/~hakan/sig.html Public Key: Try finger [EMAIL PROTECTED] Interests: WWW, Programming, 3D graphics Thought for the day: As long as one understands, the spelling does not matter :-) - -- -BEGIN PGP SIGNATURE- Version: 2.6.3i Charset: noconv iQCVAwUBMtQ+AN6dx9igIm71AQFlSQP9HAZNDMkZPy1JybjyV9oyM7GI+V2c/tDe AdE17nw9DNqOnmb0/vvpgHH61Sy9KKAhkgkp/owe8VszeHRS9KxaPhi/Ebk02/Ms jw/SBLawyy62Xqhnf0iaqJe8y9QTuYNUEDglGo8yDrm2wsgdTsDdcoR0VgQONne/ 2Mfthkrlf0A= =ylDi -END PGP SIGNATURE- -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
On Wed, 8 Jan 1997, Rick Macdonald wrote: Chad Zimmerman wrote: Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Are you an Emacs user? Emacs has dired-do-query-replace, which is on the Operate drop-down mouse menu in dired-mode. You'd have to execute it once for each change to me made, but at least it would do all the files each time. Wow! For a modeless editer, emacs sure has a lot of modes! In any reasonable vi clone (e.g. nvi, vim, elvis, etc.) you have basically two modes: insert and command. If your in insert, hit the escape key to get into command mode. Then just type a colon : and enter %s/text to replace/text to replace with/g. This is pretty standard syntax for this sort of thing in unix. The % is a short cut for specifying all lines in the file which could be done with 1,$ longhand. The s is swap or switch or something like that. The first slash marks the begginning of the search text. The second slash separates that from the replacement text and the last ends the text spec. The g indicates a global operation for each line specified (in this case all lines). The global specification is needed if you want all incidents of the search text on each line replaced. So, in vi just type: :%s/whatever/whatever else/g Very simple. The text can contain pretty much anything, but some stuff may need to be esaped with a back slash \ or input as is with a ^Vcharacter. Outside of that, I'm sure there must be some handy HTML editors that can do this as well. Thanks Richard G. Roberto [EMAIL PROTECTED] 011-81-3-3437-7967 - Tokyo, Japan -- *** Bear Stearns is not responsible for any recommendation, solicitation, offer or agreement or any information about any transaction, customer account or account activity contained in this communication. *** -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
From: Chad Zimmerman [EMAIL PROTECTED] Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Hopefully you'll get a more general answer too, but if you are an Emacs user, you probably want to know about this method: Outside of emacs, run etags, giving it the names of all the files in the subtree. For exapmle: cd wherever etags `find -type f` The in emacs, use the tags-query-replace command. (For this use of etags, the point is just to list all the files. It doesn't matter whether etags and emacs recognize any tags within the files.) Daniel P.S. This probably should go to a general Unix list, since it's not a specific Debian question. P.P.S. And it's probably in somebody's FAQ list somewhere, or should be, since it is asked once in a while. -- Daniel S. Barclay Compass Design Automation, Inc. [EMAIL PROTECTED] Suite 100, 5457 Twin Knolls Rd. Columbia, MD 21045 USA -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. Well, this is so easy to do in perl that I just write little programs to do it on the fly most of the time. Here's a little program that may do what you want: #!/usr/bin/perl -i.bak $find=shift; $replace=shift; while () { s/$find/$replace/g; print } Name it replace and call it like so: replace from to file [file ...] It can operate on multiple files, 'from' is the string you want to find, and it is replaced globally with 'to' in all the files. Backups are saved with a .bak extention. -- #!/bin/perl -sp0777iX+d*lMLa^*lN%0]dsXx++lMlN/dsM0j]dsj # RSA-3-lines-perl $/=unpack('H*',$_);$_=`echo 16dio\U$kSK$/SM$n\EsN0p[lN*1 # Joey Hess lK[d2%Sa2/d0$^Ixp|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) # [EMAIL PROTECTED] He. He. He. - - Herman Toothrot -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]
Re: Multible search and replace?
On Wed, 8 Jan 1997, Chad Zimmerman wrote: Was just wondering if there is a package out that does multiple file search and replaces? I have to go through my main html directory and make a lot of repetive changes. Was wondering if there was a package or a perl script laying arround to do this. Would same me the time of writing one up. sounds like a job for an ed script embedded within a sh script :-) something like: --cut here- #! /bin/sh for i in *.html ; do cat __EOF__ | ed -s $i s/SEARCH/REPLACE/g (and/or any other ed commands you might need here. just about anything you can do in vi you can do here) wq __EOF__ done --cut here- does pretty much the same job as sed but without the need for messing about with temporary files. note, the wq as the last line of the ed script is important. that's the familiar vi/ed write quit command :-) craig -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]