[pmwiki-users] search and replace over multiple / all pages
tamouse mailing lists
tamouse.lists at gmail.com
Sun Jul 8 14:31:17 CDT 2012
On Fri, Jul 6, 2012 at 1:12 PM, Vince Administration
<vadmin at math.uconn.edu> wrote:
> On Jul 6, 2012, at 8:29 AM, Clemens Gruber wrote:
>> Hi, I have to change some URLs in an existing wiki with more than hundred pages.
>> The old links is something like that
>> the new links
>> Have to do it on the wiki, no chance to do it on the remote server via redirect / htaccess I do not need any documentation of this change (history) so my idea is search and replace on file level all files under wiki.d .
> That is precisely how I would to it. What I would do (sorry if I am being to elementary)
> 1. Copy a couple of files to one of my experimental directories to check out the script.
> 2. Write a short shell script to search./replace in an individual file. For this I would probably use sed,
> Here is the script -UNTESTED-- Call the file upd.sh
> export srcstr="http ….. "
> export repstr="http … "
> sed -i s/$srcstr/$repstr/g $1
> This will edit inplace, so you should have backups.
> The usage is of course
> upd.sh filenametoupdate
> Test it on your test files to see if it works as you want it to.
> Then you can use find or foreach to run it on all your files.
>> Are there any side effects you think not do do it this way? Are there more elegant ways (e.g. with documentation as diff) to do this?
>> Is there any script where I can specify old (search for) and new (replace with) text parts
>> http://example.com/aaaaaa/bbbb/more-stuff.html?x=1&y=2&y=3 | http://example.com/hhhhhh/jjjj/more-stuff.html?x=1
>> http://example.com/aaaaaa/bbbb/more-stuff.html?x=4&y=5&y=6 | http://example.com/hhhhhh/jjjj/more-stuff.html?x=4
>> http://example.com/aaaaaa/bbbb/more-stuff.html?x=7&y=8&y=9 | http://example.com/hhhhhh/jjjj/more-stuff.html?x=7
>> pmwiki-users mailing list
>> pmwiki-users at pmichaud.com
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
I've run mass updates on some of my wikis several times. The method
described above works really well for simple things like a
search-and-replace edit. One thing to be very careful of, if either of
your match or replace strings contains the special characters used in
containing the wiki text, you have to make sure to treat them
specially. These are, percent: encoded to %25, newline: encoded to
%0a, and < encoded as %3c. Also, when you are running something like
sed/awk/perl etc to make the changes, make sure to only select the
line beginning with text= as that is the line where the wiki page text
I don't bother scripting these, since they're usually one-liners:
sed -i '/^text=/s/original/replaced/g' Group.*
The sed's -i option creates a .bak file so you can recover from a mass
edit like this if you want to. I still tend to make a backup
beforehand just to be safe.
* http://www.pmwiki.org/wiki/Cookbook/BulkReplace (although if you
don't use Emacs, it's not that valueable)
More information about the pmwiki-users