1
I recently moved about 30k images from Picasa to imgur . I need to replace all those links in my wordpress blog . I have exported all the posts to xml file ( it is 96mb) . I tried this powershell command (taken from one of su's question ) to test its working and it took about 5 mins to replace just one url .
(Get-Content test.txt) | ForEach-Object { $_ -replace "foo", "bar" } | Set-Content test2.txt
Any other way to replace thousands of url quickly ? Platform - Windows 7 . Can install any software needed .
You could use
sed.exe
: there are a number of Windows ports of this Unix utility, including in Microsoft's Services for Unix. To produce an edited copy of test1.txt in test2.txt, usesed <test.txt "s/foo/bar/g" >test2.txt
. It should be pretty quick, as it simply reads each line and writes the edited version all in a single pass, but I don't know how it will perform if there are no new-lines in the source file, which would cause a problem for any text editor. – AFH – 2014-11-14T11:58:00.283I have this port http://unxutils.sourceforge.net/ . And tried command from this question http://stackoverflow.com/questions/7555707/find-and-replace-a-url-with-grep-sed-awk . It didn't work for me . Your command and the one in the question look different .
– Renuka – 2014-11-14T12:04:13.927That command is basically the same as mine, except that I used standard input instead of passing the file name as a parameter. The syntax of the edit strings may be quite complex, depending on how many special characters (like
.
) are used which are of special meaning in regular expressions. It might also be better to use a delimiter character other than/
, as this will occur quite often in URLs (eg"s:foo:bar:g"
). – AFH – 2014-11-14T12:18:33.007I changed ' for that questions' answer to " ( like in your command " and it worked for a single replacement . How do I make it work multiple lines ? – Renuka – 2014-11-14T12:21:19.560
The reason for the different quotes is that single-quote in Unix has a special meaning which which it doesn't have in Windows. You will need to give some examples of what you want to replace by what in order to see what is going on. – AFH – 2014-11-14T12:29:02.243
I tried a single command like this
And it worked . For 30k urls I created a batch script like this
echo sed "s/http://www.picasa.com/dogs.png/http://i.imgur.com/blabla.jpg/g" x.xml > y.xml sed "s/http://www.picasa.com/cats.jpg/http://i.imgur.com/haha.jpg/g" x.xml > y.xml pause
This gives me error "sed is not recognized as internal or external command " . – Renuka – 2014-11-14T12:34:49.507
I can't make out what your command is meant to do, perhaps because of the format restrictions in comments. But your single command will replace every instance of
http://www.picasa.com/dogs.png
inx.xml
(though the.
should be\.
). You can move the discussion to chat if you want, but I am going out shortly and won't be back for around 7 hours. – AFH – 2014-11-14T13:03:28.750Let us continue this discussion in chat.
– Renuka – 2014-11-14T13:07:08.360