.NET (29) Archiving (10) ASP.NET (9) Books (3) C Sharp (30) Code Generation (3) Dasblog (16) Design Patterns (4) Development (37) Exchange (14) Family (10) GPS (7) Hardware (10) mixuk07 (1) Mountaineering (7) MSCRM (6) Office (3) Outlook (13) Personal Development (4) PHP (4) PowerShell (7) Productivity (9) RSS (15) Running (2) Scripting (20) SCRUM (3) Service (3) Software (60) Support (17) TaHoGen (2) Technical (50) Tools (13) Twitter (5) Web (16) Windows 7 (4) Windows Mobile (10) WS* (1)
Sign In
A while back I restructured my website so that this blog no longer started at the root, instead starting from /blog. This was so that I could introduce some other web apps and have a subfolder for projects etc.
One of the pains of this restructure was modifying all the links - I thought I had caught all this with a Redirector HttpModule, but recently realised that for some reason I had not caught images embedded in the posts themselves.Also it was becoming a pain having to remember to include the HttpModule in my web.config everytime I upgraded my blog (dasBlog)
I wanted it fixed properly this time, so grabbed a copy of all the XML files in my 'content' folder, copied them to a local folder and cracked open PowerShell...
I wanted every instance of www.mywebsite.com changed to www.mywebsite.com/blog - not difficult, but this would also change valid urls such as www.mywebsite.com/blog/page.aspx to www.mywebsite.com/blog/blog/page.aspx (note the /blog/blog in the url)
So I got everything I needed done with two 'one liners' in PowerShell...
dir | %{ $a = get-content $_ ; $a = $a -replace ("www.mywebsite.com", "www.mywebsite.com/blog") ; set-content $_ $a }
...and...
dir | %{ $a = get-content $_ ; $a = $a -replace ("www.mywebsite.com/blog/blog", "www.mywebsite.com/blog") ; set-content $_ $a }
All fixed...
Dear Ken,Thanks for the tip regarding replacing strings within a text file.Is there a way to specify multiple replacement strings? In UNIX SEd, you can specify the old and new string within a text file. Rather than wrting a bunch of one-liners, I was hoping to find a means to change multiple strings via a one-liner.Sincerely,Mike Ramirez
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u