Does awk ever resolve params ?..

Hi,
Does awk ever resolve params in the search pattern?..
The following awk doesnt know how to resolve ${tables[$j]}$ inside a loop.

k=`awk '/${tables[$j]}$/ ${graph[$i]}`

The search pattern has ${tables[$j]}$ and I am narrowing down my search with a $ at the end of string.
So...this leaves me with a question on if awk ever resolve the params in the search patterns?...I am sure it resolves in other places...like in this case ${graph[$i]}

Thx !

what are these: ${tables[$j]}" and "${graph[$i]}"?
Shell variables?

Hi vgersh,
"${tables[$j]}" and "${graph[$i]}" are 2 arrays holding 2 distinct sets of elements like table list and graph list.
A simplified code snippet giving a better idea...

#! /bin/ksh

count1=`ls -lart P*.ksh | awk '{print $9}' | wc -l`
list1="`ls -lart P*.ksh | awk '{print $9}'`"
set -A graph $list1

count2=`wc -l read_table.dat | awk '{print $1}'`
list2="`cat read_table.dat`"
set -A tables $list2

j=0

while ((j<$count2))
do
  i=0
 while ((i<$count1))
   do
   k=`awk '/ETL_VW_SCHEMA/ && /[.]${tables[$j]}$/ || /EDW_DB_SCHEMA/ && /[.]${tables[$j]}$/' ${graph[$i]}`
       ((i=i+1))
   done
  ((j=j+1))
done

Awk in the inner most loop doesnt resolve ${tables[$j]} during the run time....but no issues with ${graph[$i]}.
Hope this gives a better idea on the problem...

Thx !

k=`awk -v t="${tables[$j]}" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" t "$") / || /EDW_DB_SCHEMA/ && $0 ~ ("[.]" t "$")' ${graph[$i]}`

NOTE: as always, if on Solaris, use 'nawk' or '/usr/xpg4/bin/awk' instead of the old 'awk'.

Why are you using -l then removing all the details? You are calling 2 unnecessary external commands.

count1=`ls -art P*.ksh | wc -l`
list1=`ls -art P*.ksh`

Why are you using the -a option? Your pattern cannot match any dot files.

In fact you are using more than 2 UECs:

set -- P*.ksh
count1=$#
list1=`ls -rt P*.ksh`

There's no need for awk:

count2=$( wc -l < read_table.dat)

I recommend using the standard syntax:

while [ $j -lt $count2 ]

I recommend using the standard syntax:

i=$(( $i + 1 ))

Variables are not expanded inside single quotes.

To pass a shell variable to awk, use the -v option:

awk -v x="${tables[$j]}" '...'

Hi Johnson/Vgersh,
Thank you very much for the suggestions and the pointers..
But my shell errors out with the awk syntax....here are some quick details on my OS and the actual error itself...I tried switching my shell to ksh and run it but still errors out the same way as mentioned below.

$ awk -v t="B1_STAT_HIST" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" t "$")  || /EDW_DB_SCHEMA/ && $0 ~ ("[.]" t "$")' PDEWG300_B1_STAT_HIST.ksh
awk: syntax error near line 1
awk: bailing out near line 1

$ uname -a
SunOS xspetl01 5.8 Generic_117350-36 sun4u sparc SUNW,Sun-Fire-480R

Appreciate your suggestions !
Thx !

Oh sorry....my bad !
nawk works perfect in this case.

Thank you so much for your time..

Before we close this thread:

k=`nawk -v t="${tables[$j]}" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" t "$") / || /EDW_DB_SCHEMA/ && $0 ~ ("[.]" t "$")' ${graph[$i]}`

Few of my table occurences(${tables[$j]}) are in lower case and this script doesn't quite catch them....and I need the command to take care of lower cases too with the present functionality.
I could have researched on this, but due to time crunch not able to...
Thx !

Use patterns that match both upper and lower case: [Ee][Tt][Ll]...

Hi Johnson,
I am using an array({tables[$j]}) to store all the table names, which means I dont have the luxury of using the exact patterns like [Ee][Tt][Ll].
There are around 200 tables in the list...
So, Is there a way I can direct the shell to convert the lower cased table names to uppercase as soon as it parses and apply the awk command ?.....

Thx !

If I understand correctly you can convert them to upper case inside awk:

nawk -v t="${tables[$j]}" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" toupper(t) "$") / ...

But I also believe that you can write the entire program in awk instead of using this inefficient shell/awk mix.

Radoulov,

nawk -v t="${tables[$j]}" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" toupper(t) "$") / ...

This will not work in my case as my table list is always in upper case and 90% of the pattern occurences in the search file will be in upper case but there are few cases(which are unknown) where the occurences will be in lower case and we need to address such instances....I guess we need to write up a condition inside awk to check for the case.

Thx !

Just to mention...
I know we can just put in a seperate OR in the awk to check for lower case and resolve the issue:

nawk -v t="${tables[$j]}" '/ETL_VW_SCHEMA/ && $0 ~ ("[.]" toupper(t) "$") || /ETL_VW_SCHEMA/ && $0 ~ ("[.]" tolower(t) "$")' && .....

But I am sure this will not be a suggestable solution....

Thx !

Or just use:

toupper($0) ~ "[.]" toupper(t) "$"