NEW: need help with nawk using -v vars


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting NEW: need help with nawk using -v vars
# 8  
Old 04-24-2008
The variable TG is not use in the sample of your awk program.
Show us the full awk program.

Jean-Pierre.
# 9  
Old 04-24-2008
Quote:
Originally Posted by wakhan
ANYBODY PLEASE REPLY !!!!!!!!


Regards,
Waqas Ahmed
Pls don't bunp-up posts - it's against the Rules.

Last edited by vgersh99; 04-24-2008 at 06:05 PM.. Reason: spelling
# 10  
Old 04-24-2008
Below is my complete code, what i want is to take Trunk Group in the input and pass it to nawk (BEGIN). Below mentioned code is not giving any output.

Also see code below which gives perfect output, if i give TG
simple value like TG=700.


Code:
KarachiOMP adnan> vi tgcmp602
#!/bin/sh
#
#  Variable TG has to be set according to the trkg desired.
#
#  Also the rop file has to be updated according with the date
#  ander analysis.
#                       ie:
#                       /omp-data/logs/5etr/yymmdd.APX
#
##############################################
# Get the date stamp you want
##############################################
CurrentDate=`date +%y%m%d`
echo "Enter Search Date [$CurrentDate]:"
read SearchDate
if [ "$SearchDate" = "" ]
then
   SearchDate=${CurrentDate}
fi

echo "Enter TRUNK GROUP:"
read TGR

cat /omp-data/logs/5etr/$SearchDate.APX | nawk -F"|" -v P=$TGR  '

BEGIN {

TG=P;
        printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR NTWCONG\n");
}

/TRFTR TGCOMP/ {
        getline; getline;
        split($2,a,"-");

        date=a[2]a[3];

        getline; getline; getline;

        interval=$2; split($3,a,":"); start=a[1]; split($4,a,":"); end=a[1];

}

/TGN    ISEIZE/ {

        getline;

        tgn=$1; iseize=$2; isattmp=$5; ians=$6;

}

/TGN    OATTMPT/ {

        getline;

        oattmpt=$2; ovfl=$4; oseize=$5; osattmp=$7;

}

/TGN    OANS/   {

        getline;

        oans=$2; totusg=$3;

}

/TGN    BWOUTU/ {

        getline;

        oosmtce=$4;

        oos=$5;

}

/TGN    DBLSZR/ {

        getline;

        dblszr=$2;

}

/TGN    SBBSY/  {

        getline;

        ntwcong=$4;

}


/TGN    TRKNAV/ {

        if (tgn==TG) {

        printf("%s %2d %2d %2d %4d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", date, interval, start, end, tgn, iseize, isattmp, ians, oat

        printf("%s %2d %2d %2d %4d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", date, interval, start, end, tgn, iseize, isattmp, ians, oat
tmpt, ovfl, oseize, osattmp, oans, totusg, oosmtce, oos, dblszr, ntwcong);

        }

}


END {

} '

exit
:q!



Code below which gives perfect output, if i give TG
simple value like TG=700.



Code:
KarachiOMP adnan> vi tgcmp602
#!/bin/sh
#
#  Variable TG has to be set according to the trkg desired.
#
#  Also the rop file has to be updated according with the date
#  ander analysis.
#                       ie:
#                       /omp-data/logs/5etr/yymmdd.APX
#
##############################################
# Get the date stamp you want
##############################################
CurrentDate=`date +%y%m%d`
echo "Enter Search Date [$CurrentDate]:"
read SearchDate
if [ "$SearchDate" = "" ]
then
   SearchDate=${CurrentDate}
fi

#echo "Enter TRUNK GROUP:"
#read TGR

cat /omp-data/logs/5etr/$SearchDate.APX | nawk '

BEGIN {

TG=700;
        printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR NTWCONG\n");
}

/TRFTR TGCOMP/ {
        getline; getline;
        split($2,a,"-");

        date=a[2]a[3];

        getline; getline; getline;

        interval=$2; split($3,a,":"); start=a[1]; split($4,a,":"); end=a[1];

}

/TGN    ISEIZE/ {

        getline;

        tgn=$1; iseize=$2; isattmp=$5; ians=$6;

}

/TGN    OATTMPT/ {

        getline;

        oattmpt=$2; ovfl=$4; oseize=$5; osattmp=$7;

}

/TGN    OANS/   {

        getline;

        oans=$2; totusg=$3;

}

/TGN    BWOUTU/ {

        getline;

        oosmtce=$4;

        oos=$5;

}

/TGN    DBLSZR/ {

        getline;

        dblszr=$2;

}

/TGN    SBBSY/  {

        getline;

        ntwcong=$4;

}


/TGN    TRKNAV/ {

        if (tgn==TG) {

        printf("%s %2d %2d %2d %4d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", date, interval, start, end, tgn, iseize, isattmp, ians, oat

        printf("%s %2d %2d %2d %4d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d %6d\n", date, interval, start, end, tgn, iseize, isattmp, ians, oat
tmpt, ovfl, oseize, osattmp, oans, totusg, oosmtce, oos, dblszr, ntwcong);

        }

}


END {

} '

exit
:q!


Please Help...

Regards,
Waqas Ahmed
# 11  
Old 04-25-2008
For debugging purpose, add some display to check to value of your variables.
Code:
echo "Enter TRUNK GROUP:"
read TGR

echo "TGR=<$TGR>"

cat /omp-data/logs/5etr/$SearchDate.APX | nawk -F"|" -v P=$TGR  '

BEGIN {

TG=P;
printf("AWK - P=<%s> String_TG=<%s> Number_TG=%d\n", P, TG, TG);

        printf ("DATE IN ST EN  TGN ISEIZE ISATMP   IANS OATMPT   OVFL OSEIZE OSATMP   OANS TOTUSG OOSMTCE   OOS DBLSZR NTWCONG\n");
}

Jean-Pierre.
# 12  
Old 04-25-2008
For debugging purpose, I add some display to check values of variables.

KarachiOMP adnan> ./tgcmp602
Enter Search Date [080426]:
080425
Enter TRUNK GROUP:
700
AWK - P=<700> String_TG=<700> Number_TG=700
DATE IN ST EN TGN ISEIZE ISATMP IANS OATMPT OVFL OSEIZE OSATMP OANS TOTUSG OOSMTCE OOS DBLSZR NTWCONG

The value in the variable is going correctly, but i still dont know that why desired output is not coming.

Below is code, which gives perfect output

cat /omp-data/logs/5etr/$SearchDate.APX | nawk '

BEGIN {

TG=700;

printf ("DATE IN ST EN TGN ISEIZE ISATMP IANS OATMPT OVFL OSEIZE OSATMP OANS TOTUSG OOSMTCE OOS DBLSZR NTWCONG\n");
}

But i dont know why this simple script dont give output.


echo "Enter TRUNK GROUP:"
read TGR

echo "TGR=<$TGR>"

cat /omp-data/logs/5etr/$SearchDate.APX | nawk -F"|" -v P=$TGR '

BEGIN {

TG=P;
printf("AWK - P=<%s> String_TG=<%s> Number_TG=%d\n", P, TG, TG);

printf ("DATE IN ST EN TGN ISEIZE ISATMP IANS OATMPT OVFL OSEIZE OSATMP OANS TOTUSG OOSMTCE OOS DBLSZR NTWCONG\n");
}


ANY IDEA..

PLZ HELP !!!


Regards,
Waqas Ahmed
# 13  
Old 04-25-2008
Why don't you define the field separator FS in same manner in the two cases ?

When you the value to 700, the field separator is omited, so its value is space.
Code:
cat /omp-data/logs/5etr/$SearchDate.APX | nawk '

When you use the TGP variable, the FS is set to '|' :
Code:
cat /omp-data/logs/5etr/$SearchDate.APX | nawk -F"|" -v P=$TGR '

Jean-Pierre.
# 14  
Old 04-25-2008
I think you are asking that why i define field separator FS like this:-F"|" -v P=$TGR ' in the script which is not working .
Code:
cat /omp-data/logs/5etr/$SearchDate.APX | nawk -F"|" -v P=$TGR '

so sir actually i am modifying my old script which is this:
Code:
cat /omp-data/logs/5etr/$SearchDate.APX | nawk '
BEGIN {
TG=700;
printf ("DATE IN ST EN TGN ISEIZE ISATMP IANS OATMPT OVFL OSEIZE OSATMP OANS TOTUSG OOSMTCE OOS DBLSZR NTWCONG\n");
}

the problem with this script is this , that every time we have to open the script file with vi and change the value of TG like 700,701, 702 etc..which is not easy for normal user. so i just want to modify the script so it takes input of TG at the startup and gives the output.

For debugging purpose we have seen that P variable is getting right value.
but i dont know why its not working.
Code:
KarachiOMP adnan> ./tgcmp602
Enter Search Date [080426]:
080425
Enter TRUNK GROUP:
700
AWK - P=<700> String_TG=<700> Number_TG=700
DATE IN ST EN TGN ISEIZE ISATMP IANS OATMPT OVFL OSEIZE OSATMP OANS TOTUSG OOSMTCE OOS DBLSZR NTWCONG

Please share if you have some other idea in mind to solve the problem.

Regards,
Waqas Ahmed
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read vars iteratively

Hello, I have a tab delimited list of 311 server & account names which I want to read those 2 variables and then connect to each server and get info on that particular job account. I've tried the following: while read server acct; do printf "********$server\t $acct***********\n" ... (3 Replies)
Discussion started by: mcbobolink
3 Replies

2. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

3. Shell Programming and Scripting

List of Shell Env Vars

Hia, echo ${!S*} gives me all those env vars starting with S like SHELL SECONDS SHELLOPTS SHLVL etc. is there any way to deflate the shell variables' range like echo ${!A-E*} OR echo ${!A..S*} to list all env vars starting within range of A till E. Thanks Regards, Nasir (1 Reply)
Discussion started by: busyboy
1 Replies

4. Shell Programming and Scripting

getting vars from external files

Hi I have an issue, I want to get variables from an external file. Variable file var1=test var2-test2 I want to get these vars from another shell script. Does any one know how? (5 Replies)
Discussion started by: digitalviking
5 Replies

5. Shell Programming and Scripting

check a list of vars

I have about 20 different variables that I need to check for null values then replace with a specific string if they are null. I've been doing this via 20 different if then statements like this: if ; then WIND="UUU" fi Is there a more elegant way to do this? The vars aren't sequential in... (6 Replies)
Discussion started by: audiophile
6 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

7. Shell Programming and Scripting

Passing Vars between scripts

Im running a script that runs scripts within it self and i need to pass vars made in the original script to scripts run within it and the only way i can think to do it is right the string to a file and read the file in the script (4 Replies)
Discussion started by: rcunn87
4 Replies

8. Shell Programming and Scripting

Env vars in a SED script

Hello, <Preamble> I'm writing an installation script for use with PKGADD. What I want to do is take one of the variables set in the REQUEST script and use that in the install script so I can change applications configuration. My install script is as follows: sed ' /^DIRNAME/ i\... (8 Replies)
Discussion started by: Bags
8 Replies

9. Shell Programming and Scripting

need help with nawk using -v vars

I'm trying to pass nawk a shell variable to be used in a pattern match. I can't get this work. I'm calling nawk from a /bin/sh echo " Input file: \c" read var1 echo " Input: \c" read var2 nawk -F"|" -v x=$1 ' BEGIN $15 ~ /^'$var2'/ {print $2}' var1 {apary=$15; bparty=$23; time=$4;... (3 Replies)
Discussion started by: amon
3 Replies
Login or Register to Ask a Question