Fixed "expr: syntax error" on OSX

Replaced expr length command by awk
Added OS dependent variables