web analytics

Parsing script parameters

Quick and dirty parsing procedure for unix shell scripts

parse_command_line () { typeset -i user_opt help_opt password_opt verbose_opt typeset errmsg arg_cou=$# while [ "$#" -gt 0 ] do <strong>case "$1" in</strong> -@([U]) )  let user_opt=user_opt+1 ;; -P       )    let password_opt=password_opt+1 ; ask_pass=0 ;; -option1    )    ;; -option2    ) […]

Rev function and comma-separated output

Here is the shell command snippet to display comma-separated output:

ls -lrt | rev | sed ‘s/\\([0-9][0-9][0-9]\\)/\\1,/g’ | rev | sed ‘s/\\([\^0-9]\\),\\([0-9]\\)/\\1\\2/g;s/\^,\\([0-9]\\)/\\1/g’

Example: -rw-r—– 1 sybase dba 1,572,872,192 Feb 2 07:09 master.dbf

Rev in awk

#!/bin/ksh nawk ‘{ l=length($0) ; for(i=l;i>0;i–) { printf "%s", substr($0,i,1) } ; print "" }’

Rev function (absent on SunOS) […]