Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assignment and passing shell variable

Status
Not open for further replies.

daula

Programmer
May 29, 2006
38
0
0
US
hi everyone;
i want to take a shell variable and pass it to the -f (external file) option of awk.

i have tried a couple of ways and neither works.
btw, the reason i'm trying to achieve this is because for every input file there is an associated awk file (e.g IDA1.xml is associated to IDA1.sub etc).

any help is appreciate.

thanks in advance.

daula

Code:
TALLY="$1"
OUT_FILE="$4"
FORM="$2"
AXIS="$3"
.
.
.

function func ()
{
  echo `expr substr $TALLY 4 1`
}

my_id=`eval func`
sub="IDA$my_id.sub"

1) 
awk -v FORMAT="$FORM" -v xAXIS="$AXIS" -f '"$sub"' "$TALLY" > "$OUT_FILE"

2) 
awk -v FORMAT="$FORM" -v xAXIS="$AXIS" -f "'"$sub"'" "$TALLY" > "$OUT_FILE"
 
And what about simply this ?
-f $sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hello again;
i have another variable related question...
in the "sub" file (mentioned in my previous post), i have an search/action like:
Code:
/:name="cState">/{++r;next}

now, i'm wondering is there a way i can pass "cState" or even the whole search string ":name="cState"" as a variable?

many thanks

daula
 
Replace this:
/:name="cState">/{++r;next}
with this:
$0~":name=\""vName"\"">/{++r;next}

And then:
awk -v FORMAT=$FORM -v xAXIS=$AXIS -v vName=cState -f $sub $TALLY > $OUT_FILE

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank PHV
although awk complained "unterminated regexp" and "unexpected newline".
i mananged to fix it tho...

$0~":name=\""vName"\">"/{++r;next}

thanks again for lead/tip

daula
 
OOps, sorry for the typo:
$0~":name=\""vName"\">"{++r;next}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top