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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am trying to pass an argument to

Status
Not open for further replies.

shaokat

Technical User
Oct 8, 2002
11
IN
I am trying to pass an argument to a script and use that argument in an awk statement. Is there something missing in the code? Its not working! It is creating a file with blank extension.

TIA
-KAT


#!/usr/bin/ksh

if [ $# != 2 ] ;then
echo "usage: $0 argument"
exit
fi

ch_ind="$1" ;export ch_ind
ind_pos="$2" ;export ind_pos


ProcessFiles (){
echo GetFiles

for i in *.svd
do

awk 'BEGIN { count=0;}
{
print_ind=substr($0,'$ind_pos', 1);
if (print_ind=="Y") {
if (count > 0) {
printf("\r\n") > "file."'ch_ind'
}
count=1;
printf("%s", $0) > "file."'$ch_ind'
}
}
' < &quot;$i&quot;
done

}

ProcessFiles
echo done
 
Kat:

You're shell variables within the awk script has to be protected by two double quotes:

Check out this FAQ on the 3 methods for using variables in awk.

&quot;&quot;$ch_ind&quot;&quot;

faq271-1281

Regards,

Ed
 
or:

nawk -n ind_pos=${ind_pos} 'BEGIN { count=0;}
{
print_ind=substr($0,ind_pos, 1);
........
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops - sorry 'bout that:

nawk -v ind_pos=${ind_pos} 'BEGIN { count=0;}
{
print_ind=substr($0,ind_pos, 1); vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top