[pmwiki-users] search and replace over multiple / all pages
vadmin at math.uconn.edu
Fri Jul 6 13:12:00 CDT 2012
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
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
More information about the pmwiki-users