Put a scripting language in your life

I think my first scripting language was something called ARexx in my old Amiga 1200. I used to write ARexx script for environment tunning.
After that the Bourne Again Shell (BASH) has been REALLY handy in the past years as I was working always in unix environments (mainly Linux) and BASH along with AWK and Sed, Grep, etc.. are extremly powerful tools, I'd say a must. In fact, they are still my favorite tools in Linux for system scripts.
Along with BASH I used to do some scripting in Python and Perl but I don't like Perl at all, is is too weird and difficult to maintain :-).
I think scripts are a key to boost productivity sometimes, i.e, everytime you need to generate code, use regular expressions, or just to write something quick. They are good even to write a complex applications or systems, it just depends on your problem. Said that, I'm afraid a lot of C# developers do not use scripting languages at all and this is a mistake in my opinion.
Now that I'm working on Windows I felt a bit lost without my bash and all the GNU tools so I installed them thanks to the
GNUWin32 project and the Win-Bash but unfortunately I miss a lot of features (the bash is not the same actually). I've concluded that it is better to use Python on Windows (for all the scripting) rather than Bash.

Here you go a nice script to find regular expressions on .cs files and replace them with other regular expressions.
You only have to run the script from your solution root folder in order to go into every csharp file recursively.
You can do things like that:

C:\>python recursiveReplace.py 1 "(\S+)\.(\S+)\.Key\s+" "\1.BusinessDefinition.\2"
The former expression change this: Something.AnotherThing.Key
For this: Something.BusinessDefinition.AnotherThing

C:\>python recursiveReplace.py 1 "SomeString[0-9]" "SomeStringWithoutNumbers"
The former expression change this: Something9
For this: Something

I'd like to think that you were not changing your code manually in the places in which you can just use a regular expression to replace 🙂

Don't worry if you don't know Python and regular expressions: http://www.amk.ca/python/howto/regex/regex.html

Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
  • http://www.migranpipa.net oscar

    Hi Carlos, I cannot download the script.

    Good blog, good job.

    Regards.

    Oscar.

  • http://carlosble.com Carlos Ble

    Hi Oscar!!!
    Thanks man, I’ve fixed it: http://carlosble.com/downloads/recursiveReplace.zip

    Best regards mate!