Trying to execute a expression in a variable

Hi

i tried to execute a below script but it is giving execution error

rec=ABC,1234,55.00
Colno=2
coldel=,

fd='"'$coldel'"'
fprint="'"'{print$'$colno'}'"'"

colsyn=`echo "echo "$rec "| awk -F"$fd $fprint`

echo column syntax is $colsyn

colrec=`colsyn`

echo column is $colrec

================================

am getting syntax echo as

echo ABC,1234,55.00 | awk -F"," '{print$2}'

my expected output is

column is 1234

Please help

Thanks in advance

try

echo "ABC,1234,55.00" | awk -F, '{print$2}'

I cant able to hard code i need to execute from the user defined variable,

i tried but it is not working

What kind of a useless jugglery is this? :smiley:
You may try:

colsyn=`echo "$rec"|awk -F"$coldel" '{print $colno}' colno="$colno"`
rec=ABC,1234,55.00
Colno=2
coldel=,

fd=$coldel
fprint=$(echo "'{print \$$Colno }'")

eval echo "echo $rec | awk -F\"$fd\" $fprint"
1 Like

again am getting the expression syntax error

---------- Post updated at 07:01 AM ---------- Previous update was at 06:57 AM ----------

thank you pravin it worked,,, thanks again