Friday, August 31, 2012

Awk script that checks duplicate values in an XML

I wanted to test if a key-combination of 3 field values appeared multiple times in an XML file. A colleague of mine gave me head start on text-processing using Awk. OS X ships with the BSD version of awk so this came out quite handy.

The input XML:


The Awk script:

print "START";
print "";
/SiebelOrderID/ {
       line = $0;
       split(line, a, ">");
       split(a[2], b, "<");
       siebelOrderID = b[1];

  #print "a" siebelOrderID;
/SiebelOrderNumber/ {
       line = $0;
       split(line, c, ">");
       split(c[2], d, "<");
       SiebelOrderNumber = d[1];

  #print "b" SiebelOrderNumber;
/CordysOrderNumber/ {
       line = $0;
       split(line, e, ">");
       split(e[2], f, "<");
       CordysOrderNumber = f[1];

       #print "c" CordysOrderNumber;

/\/Order/ { 

plep = siebelOrderID "_" SiebelOrderNumber "_" CordysOrderNumber;


#print "d" plep;



       for (i in lijst) {
        if (lijst[i]-1) {
print i, lijst[i]

print "";
print "FINISHED!";

To make life easier, I put the script in a file called "parser.awk" and then used the following command in Terminal:
awk -f parser.awk input.xml

This will print the field combinations that occur multiple times.


Batch file that loops through files

This week I had to create a batch file that loops through folders and files. Dependent on the path, I needed to create a new.SQL file and append the file names to the text file.

This is the script:


REM Creating CreateStatements Files...

@echo off

rem This script makes a CreateStatementsFiles.
rem Version: 3
rem Last script update on: 2012-08-30 by Joshua Moesa

rem Setting environment variables
set rootPathBatchFile=C:\DBSCRIPTS\
set scriptRootPath=%rootPathBatchFile%scripts\
set fileOutput=%rootPathBatchFile%output.txt
set fileOutputSub=%rootPathBatchFile%outputSubRoutine.txt

rem Cleaning-up
::Cleanup all mk_-files
FOR /R %rootPathBatchFile% %%G IN (mk_*.sql) DO (


rem Printing all SQL filenames to buffer file
FOR /R %rootPathBatchFile% %%G IN (cr_*.sql) DO echo %%G >> %fileOutput%

::echo %%~pG >> %fileOutput%

rem Processing lines in the buffer file

FOR /F "tokens=*" %%A in (%fileOutput%) do (
call :process %%A


::echo %1
set fullFileName=%1
call :parse "%fullFileName%"

goto :end

set list=%1
set list=%list:"=%
FOR /f "tokens=4,5,6 delims=\" %%a IN ("%list%") DO (
  if not "%%a" == "" call :sub %%a %%b %%c
  if not "%%b" == "" call :parse "%%b %%b %%c"


exit /b


::echo In subroutine
::echo %1 %2 %3 >> %fileOutputSub%
::echo %scriptRootPath%%1\%2\makefile.txt >> %fileOutputSub%

if not exist %scriptRootPath%%1\%2\mk_%2.sql (
 echo prompt create %2 > %scriptRootPath%%1\%2\mk_%2.sql

echo @@%3 >> %scriptRootPath%%1\%2\mk_%2.sql

exit /b


DEL %fileOutput%


Some handy references I used:

Tuesday, August 28, 2012

X2Go client for Mac: connect with Unix

At my assignment, we switched to Unix development machines. Prior to this, we developed on the Microsoft SQL Server 2003 platform so I used the excellent CoRD remote desktop client to create a RDP connections.

For our new situation we're using X2Go.
x2go is an open (GPL/AGPL) source “server based computing” project. Combining the advantages of existing systems it features ease of use, performance and scalability. x2go provides you with access to your desktop as an individual as well as a corporate user - from within your own network and via the internet. x2go is not limited to particular hardware, it supports a variety of devices and architectures. x2go is open source and open minded. Like any open source project we welcome your support

There's a good X2Go client available for Mac which I use to connect to our Unix machines. I had some startup problems due to my recent OS upgrade to Mountain Lion. I noticed that X11 isn't included in Mountain Lion, so I went to XQuartz to download the latest X11 app. After install and re-login, I then went to Preferences and modified the X-Server settings. Don't click Find X11 application because it will reset the setting incorrectly.

After fiddling around with the connection settings, I managed to connect!



Monday, August 20, 2012

Tuesday, August 7, 2012

Monday, August 6, 2012

Version control with Git and Bitbucket on a Mac

I was looking into a way to put my code into a private cloud version control system. My choice for now: bitbucket.

  • First I installed the git-osx-installer for Snow Leopard (allthough I'm running Mountain Lion now).
  • Then I created an account on bitbucket.
  • I followed the wonderful bitbucket 101 to get a grasp of the Git commands (coming from a SVN world).
  • I installed the beautiful and free SourceTree Git client
  • I created a repo on bitbucket and cloned it to my Mac.
  • Added files to my working copy and added and committed them into bitbucket.
  • Done!

Java Build path and Mac OS X Mountain Lion

After my update from Snow Leopard to Mountain Lion, my Eclipse environment build path got srewed up. My project folder icons showed a red exclamation mark which hinted me.
Have to look into it a bit further (by checking the Java for Developers packages), but I did this as a quick workaround:
  1. In Eclipse, go to Preferences
  2. At Installed JREs, add a JRE of type MacOS X VM
  3. For the JRE Home use location: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home