doing a 'for i in `cat testfile`' runs a loop for each tab separated item
trying to use awk to get a line reads my variable literally...#PASSNFO=`cat $1 | awk 'NR=="$PASSNO"'` come out on the command line as #PASSNFO=`cat $1 | awk 'NR==$PASSNO'`
and I tried using shift to push to the next 6, but that seems to be used for interpreting command line arguments and not a file.
EDIT: trying the below from ksh seems to do nothing either, it won't even echo the output of $LINE
function while_read_LINE
{
cat $1 | while read LINE
do
awk '{ for (i=1; i <= NF ; i++) {printf("$%d=%s ", i, $i) }
printf("\n") } ' inputfilename
The default names for fields in awk are:
$0 - whole line
$1 - field 1
$2 - field 2
.........
NF is the number of fields on the line.
You can substitute a variable like "i" for numbers of fields: "$i" is the field
that when i is evaluated, that field number is referenced.
I'm not sure I'm entirely clear on what you want to accomplish, so please feel free to reply so we can tweak the commands as needed. It might help to know one more standard awk variable, FNR. This is the line number. Here are a couple of examples of its use, with the data file being piped in to simplify the syntax a hair. In general, though, I'd suggest calling the data file as part of the command.
You should not use $1 as a variable name in shell - it is already reserved
That said you can create an array:
#/bin/ksh
while read line
do
set -A array $line
# at this point you have array elements that you reference with a number
# ${#array[*]} number of fields or elements in the array.
let i=0
while [[ $i -lt ${#array[*]} ]]
do
echo " field $i = ${array} \c"
i=$(( i + 1 ))
done
echo " "
done < inputfile
arrays count from zero, and go from zero to one less than the number of elements.
echo "...\c" supresses a new line, so all of the output is one one line.
allrighty, the end goal is is to create policies in netbackup, I'm going to be creating a LOT of policies very soon to where a script will make life easier.
Below is what I have as it's been edited repeatedly (so there's lots of stuff I commented out rather than delete until I figure out what works, possibly not considered the best method of hammering things out) All the commands are just echo'd right now as I don't want it to do anything until I'm sure it's submitting correct information.
The stuff in the while statement is what needs to happen for each line. Since which line needs to be read from the file advances with each pass I can't hard code an awk '[NR|FNR]==X' and putting a $PASSNO in place of 'X' didn't seem to work.
$ cat RMAN_policy.sh
#! /bin/ksh
#
# set command line variables
#
PATH=/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/netbackup/bin/goodies:/usr/openv/netbackup/bin/goodies/support:/usr/openv/volmgr/bin:/usr/openv/volmgr/bin/goodies:/opt/VRTSvxfs/sbin:$PATH
#USAGE="USAGE: RMAN_policy.sh <filename> "
Thanks for the help guys! I managed to get something working, though it was a little hectic and there's probably more graceful way of dealing with a little problem I had involving the script running once for each "word" in the flatfile instead of once for each line.
Here's the practical example should someone be interested in the future.
$ cat array.sh
#/bin/ksh
TESTFILE=$1
while read line
do
set -A array $line
# at this point you have array elements that you reference with a number
# ${#array
[]} number of fields or elements in the array.
let i=0
while [[ $i -lt ${#array
[]} ]]
do
INSTANCE=${array[0]}
i=$(( i + 1 ))
SERVER=${array[1]}
i=$(( i + 1 ))
PRIORITY=${array[2]}
i=$(( i + 1 ))
VPOOL=${array[3]}
i=$(( i + 1 ))
BPATH=${array[4]}
i=$(( i + 1 ))
OSV=${array[5]}
i=$(( i + 1 ))