awk issue expanding variables in ksh script

Hi Guys,
I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need.

I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles.

#set 2 variables below
JOBNAME=abc_def
AUTO=A12
 
#Below line creates a variable using comma as a field separator
DESC=`/bin/awk -F',' "/^$JOBNAME/" 
/apps/test/scripts/library/desc.output.$AUTO`

Content of /apps/test/scripts/library/desc.output.A12

abc_def,GHIJKLABCEQAVTCRIT AMM Clean Applogs

I am expecting $DESC variable to be the line in that file so my next variable I can print i.e.

DESC1=`echo $DESC | awk -F',' '{print $2}'` ;
TAGID=`echo $DESC1 | awk -F' ' '{print $1}'` ;

The problem is that although this works from the command line it doesn't in my ksh script. It doesn't assign anything to $DESC, presumably because it can't expand the JOBNAME and AUTO variables.

Can anyone please advise if this is just a quoting issue and if so - what syntax should work?

Thanks,
Gary

awk seems to be the wrong tool for the job for this. grep would be more straightforward. Also, you don't need to run awk 9 times to extract 9 columns from 1 line, the shell is quite capable of splitting things by itself.

OLDIFS="$IFS"
IFS=","
        set -- `grep "^$JOBNAME," /apps/test/scripts/library/desc.output.$AUT`
IFS="$OLDIFS"

echo "DESC1 is $1"
echo "TAGID is $2"
...

maybe it's the newline between `` Try with a \

 DESC=`/bin/awk -F',' "/^$JOBNAME/" \
/apps/test/scripts/library/desc.output.$AUTO`

I agree with Corona688 that awk isn't needed for this job. But, if you're just having trouble understanding how to use the various quotes, this is one way to use one invocation of awk to do the job:

#!/bin/ksh
JOBNAME=abc_def
AUTO=A12awk -F',' -v jobname="$JOBNAME" '$1 == jobname {
        printf("%s\n%s\n",$0,$2)
        sub(/ .*/,"",$2)
        printf("%s\n",$2)
}' /apps/test/scripts/library/desc.output.$AUTO | (
        read DESC        printf "DESC is \"%s\"\n" "$DESC"
        read DESC1        printf "DESC1 is \"%s\"\n" "$DESC1"
        read TAGID        printf "TAGID is \"%s\"\n" "$TAGID"
)