I love the Unix Command Line! And a tip of the hat to cygwin.

Quick sidenote: I haven’t figured out the RSS issue yet, but I did notice that I was getting picked up in bloglines. Hmmm. Maybe it was an old cached feed from when the feeds worked. I don’t know, and I haven’t had time to dig in and figure it out yet. This is just a default install of WordPress. I haven’t even changed the damn template. Argh!

Anyway, I bet you’re wondering what that subject means at the top of the post. Well, let me set the scene…

At work, we use some stupid Novell system to distribute our licensed apps. One of those apps is WebSphere, which is the app server I have to test my code against. To get WebSphere, I have to install the WebSphere Studio (basically Eclipse 2 with a $5,000 price tag). Fine, I can live with that. Now, I want to run the app server outside of WebSphere Sutdio so I can develop with Eclipse 3.0 (the free one) and deploy with ant. Shouldn’t be too complicated, right? Well, when WebSphere Studio is first installed, a bunch of server startup scripts and xml configuration files are generated for the app server. Now, the supid Novell application distribution thingie mentioned earlier installs it to a different path then I am forced to, and all of the generated batch files have the WRONG hardcoded path in them. The “good” news is it only took me about 1.5 hours to figure that out.

Now to the point of my post. I had to replace their hardcoded path with mine in all of the batch files and xml files. These files are in a myriad of directories under the main WebSphere directory. So to make a way too long story short, I wrote a short 7 line ruby script that takes a filename as an argument on the commandline and interates over each line replacing the bad path with the good one. That took about 5 minutes. I know I could’ve used sed, but I love Ruby, and I like to write Ruby scripts whenever I can. So next, I wrote a long command line to actually call the script on the appropriate files, and BAM, all done. Grand total of about 9 minutes, 4 of which were spent refreshing myself on the awk syntax. Now, how long would that have taken me if I were pointing and clicking? 😉 Anyway, I know that this isn’t anything remarkable, I just get excited when I see great tools do their job well. The whole *nix philosophy of combining simple tools that each do their jobs very well to do complex things is so awsome.

Without further ado, here’s the command:

grep -re '[cC]:[/]WebSphere[/]AppServer' . | awk -F":" '{print $1}' | awk '{print "./replace_path.rb "$O}' | bash

And here’s the trivial ruby script:

lines = []
File.open(ARGV[0],"r") do |file|
    file.readlines.each do |line|
        lines << line.gsub(/[cC]:[\/]WebSphere[\/]AppServer/,'C:/Progra~1/IBM/WebSph~1/runtimes/aes_v4')
    end
end
File.open(ARGV[0],"w") { |file| lines.each {|x| file.puts x }}

Have a nice day!

Leave a Reply