1 |
On Wednesday 30 April 2008, 17:52, Matthew R. Lee wrote: |
2 |
|
3 |
> I have a folder full of .html files and I need to go through and |
4 |
> replace in each and every one of them a couple of bits of info. I know |
5 |
> I can do this using the following from the command line: |
6 |
> sed 's/VV, ppp-ppp/81, 51-67/' file.html > newfile.html | mv |
7 |
> newfile.html file.html |
8 |
> Problem is I need to do this on nearly 200 files. I assume it could |
9 |
> be done with a script, but I have zero experience in writing scripts. |
10 |
|
11 |
If all the files are in the same directory, you can do |
12 |
|
13 |
cd /your/directory |
14 |
for f in *.html; do |
15 |
sed -i 's/VV, ppp-ppp/81, 51-67/' "$f" |
16 |
done |
17 |
|
18 |
The -i flag tells sed to edit the file "in place", ie, the changes are |
19 |
made to the file itself (of course, sed does create a temporary file |
20 |
behind the scenes, but that is handled by sed). |
21 |
To stay on the safe side, I suggest specifying a suffix to -i, so that |
22 |
sed creates backup copies of the files, eg |
23 |
|
24 |
sed -i BAK etc. |
25 |
|
26 |
will create a backup file called "$f.BAK" when modifying "$f". |
27 |
When you're sure the changes are correct, you can of course delete all |
28 |
the BAK files. Otherwise, use them to restore the original files and |
29 |
start over. |
30 |
|
31 |
Hope this helps. |
32 |
-- |
33 |
gentoo-user@l.g.o mailing list |