----------------------------------------------------------------------------- Using Awk Arguments Directly During the BEGIN{..} code block, ARGV has not been looked at, but has been read into an array. As such you can look through it an act or modify on those variables. =======8<-------- awk 'BEGIN { print "data = " data for (i=0;i<]+" '....' ----------------------------------------------------------------------------- Changing the record seperator inside an awk script. Awk reads and record separates its input before the script properly starts as such you need to get it to re-evaluate that input. For example... awk 'BEGIN { RS=";" } { $1=$1; printf "%s%1s\n",$0,";" } ' infile The $1=$1 is required to get awk to re-compute the $0 for the first record. ----------------------------------------------------------------------------- Determine which column numbers of relevant 'ps' fields =======8<--------CUT HERE----------axes/crowbars permitted--------------- #!/bin/sh CMDCOL=`ps -e | awk ' NR == 1 { for (i = 1; i <= NF; i++) if ($i == "COMMAND" || $i == "CMD" || $i == "COMD") cmdcol = i } END { print cmdcol } '` if [ "$CMDCOL" = "" ] then echo "$0: Unrecognised ps format for COMMAND field" exit 1 fi TTYCOL=`ps -e | awk ' NR == 1 { for (i = 1; i <= NF; i++) if ($i == "TTY") ttycol = i } END { print ttycol } '` if [ "X$TTYCOL" = "X" ]; then echo "$0: Unrecognised ps format for TTY field" exit 1 fi # # Print list of all terminals running program # echo -n "Terminals running vim : " ps -e | awk ' $'"$CMDCOL"' == "vim" { print $'"$TTYCOL"' }' =======8<--------CUT HERE----------axes/crowbars permitted--------------- -----------------------------------------------------------------------------