[gentoo-user] [OT]batch processing html files
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. I've looked through a few how-to's but haven't found anything I understand sofar. I want to learn how to script, but my Prof want's this done yesterday as the associated paper has just been published. Cheers Matt -- %%% Dr. Matthew R. Lee Instituto Biologia Marina 'Jurgen Winter' Universidad Austral de Chile Campus Isla Teja Valdivia [EMAIL PROTECTED] URL: meiochile.matthewlee.org %%% -- gentoo-user@lists.gentoo.org mailing list
Re: [gentoo-user] [OT]batch processing html files
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 This should work (untested!): for x in $(find YOUR-DIR-WITH-HTML-FILE -name *.htm*); do ~ tmp=$(mktemp); ~ sed 's/VV, ppp-ppp/81, 51-67/' $x $tmp mv $tmp $x; ~ rm $tmp; done Matthew R. Lee schrieb: | 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. I've looked | through a few how-to's but haven't found anything I understand sofar. I want | to learn how to script, but my Prof want's this done yesterday as the | associated paper has just been published. | Cheers | Matt - -- Johann Schmitz http://www.j-schmitz.net -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAkgYl40ACgkQZsUt7MqpQk0B4ACfdSv5T9h3kd45vseh3vKg5vun ga4AoKL6nnAiobGsWIwHgND7DChxUNy6 =ESvU -END PGP SIGNATURE- -- gentoo-user@lists.gentoo.org mailing list
Re: [gentoo-user] [OT]batch processing html files
On Wednesday 30 April 2008, 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. I've looked through a few how-to's but haven't found anything I understand sofar. I want to learn how to script, but my Prof want's this done yesterday as the associated paper has just been published. Cheers Matt bash to the rescue! try for: for n in *html ; do sed 's/VV, ppp-ppp/81, 51-67/' $n newfile.html ; mv newfile.html $n ; done That assumes that every html file in the current dir that contains VV must have it changed. Adapt as needed :-) Somehow somewhere you can accomplish what you want in one line with a suitable combination of locate, find, grep, for, xargs, sed and awk -- Alan McKinnon alan dot mckinnon at gmail dot com -- gentoo-user@lists.gentoo.org mailing list
Re: [gentoo-user] [OT]batch processing html files
On Wed, Apr 30, 2008 at 11:52:10AM -0400, 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 If all your files are in the same folder: sed -i.bkup 'YOUR SED EXPRESSION' *.html This will edit the files in place, and keep a backup copy at filename.html.bkup so if you fouled up on your expression, you can restore sanity by rename .html.bkup .html *.html.bkup if all of your html files are named sanely. HTH, W -- Willie W. Wong [EMAIL PROTECTED] 408 Fine Hall, Department of Mathematics, Princeton University, Princeton A mathematician's reputation rests on the number of bad proofs he has given. -- gentoo-user@lists.gentoo.org mailing list
Re: [gentoo-user] [OT]batch processing html files
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
Re: [gentoo-user] [OT]batch processing html files
On Wed, 30 Apr 2008 18:00:13 +0200, Johann Schmitz wrote: sed 's/VV, ppp-ppp/81, 51-67/' $x $tmp mv $tmp $x; Use sed -i to save messing around with temporary files yourself. -- Neil Bothwick Lottery: A tax on people who are bad at math. signature.asc Description: PGP signature
Re: [gentoo-user] [OT]batch processing html files
On Wed, Apr 30, 2008 at 06:02:38PM +0200, Penguin Lover Alan McKinnon squawked: On Wednesday 30 April 2008, 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 Somehow somewhere you can accomplish what you want in one line with a suitable combination of locate, find, grep, for, xargs, sed and awk Right, as an addendum to my other solution, in the case where files are spread across a directory tree, run the following in the base directory of tree: find ./ -name *.html -exec sed -i.bkup 's/VV, ppp-ppp/81, 51-67/' {} + (yes, that's a '+' character at the end). You can, of course, tweak the parameter to find to get finer control of exactly which files you want modified; this is left as an exercise to the reader. W -- Introducing: the Universal Conterexample Matrix [ 0 1 ] [ 0 0 ] if you ever suspect a statement is false for linear transformations, it will be false for the Universal Counterexample Matrix. ~Prof. Edward Nelson. MAT 217. P-town Sortir en Pantoufles: up 509 days, 14:49 -- gentoo-user@lists.gentoo.org mailing list
Re: [gentoo-user] [OT]batch processing html files
On Wednesday 30 April 2008 12:00:13 Johann Schmitz wrote: This should work (untested!): for x in $(find YOUR-DIR-WITH-HTML-FILE -name *.htm*); do ~ tmp=$(mktemp); ~ sed 's/VV, ppp-ppp/81, 51-67/' $x $tmp mv $tmp $x; ~ rm $tmp; done Matthew R. Lee schrieb: | 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. I've | looked through a few how-to's but haven't found anything I understand | sofar. I want to learn how to script, but my Prof want's this done | yesterday as the associated paper has just been published. | Cheers | Matt -- Johann Schmitz http://www.j-schmitz.net Thanks, job done. All the variations suggested worked, I tried them all :-) I love the command line, I really need to learn how to make the most of it. Saludos from Chile Matt -- %%% Dr. Matthew R. Lee Instituto Biologia Marina 'Jurgen Winter' Universidad Austral de Chile Campus Isla Teja Valdivia [EMAIL PROTECTED] URL: meiochile.matthewlee.org %%% -- gentoo-user@lists.gentoo.org mailing list