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
# 1  
Old 04-21-2008
NEW: 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

I want that when somebody enters Trunk Group in variable TGR so it goes into nawk variable TG.


Code:
echo "Enter TRUNK GROUP:"
read TGR

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

BEGIN {

       TG=$P;

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

PLEASE can anyone help me out with this code somehow it does not work..
THANKS in advance

Last edited by Yogesh Sawant; 04-21-2008 at 05:19 AM.. Reason: added code tags
# 2  
Old 04-21-2008
Code:
echo "Enter TRUNK GROUP:"
read TGR

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");
}
 . . . . .
' /omp-data/logs/5etr/$SearchDate.APX

Jean-Pierre.

Last edited by aigles; 04-21-2008 at 09:08 AM.. Reason: remove cat command
# 3  
Old 04-21-2008
Can you please tell me that do i have to convert variable P into integer in BEGIN. Because now it is running but giving no output.
Actaually value of P should be like 700, 701, 744, 601 like this..

echo "Enter TRUNK GROUP:"
read TGR

cat | 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");
}
. . . . .
' /omp-data/logs/5etr/$SearchDate.APX
# 4  
Old 04-21-2008
Where is the cat command for?

Regards
# 5  
Old 04-21-2008
I moved the input filename on the awk command, but i forgot to remove the cat command.
Code:
cat | nawk -F"|" -v P=$TGR '

Jean-Pierre.
# 6  
Old 04-23-2008
I am trying to make a simple script in which i take input from shell and then forward the value to
nawk (BEGIN).

but when i run below mention script so it give no output.


Code:
Code:
echo "Enter TRUNK GROUP:"
read TGR

cat /omp-data/logs/5etr/080422.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");
}


But when i run below code , so its work fine.

Code:
Code:
#echo "Enter TRUNK GROUP:"
#read TGR
#cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR '

cat /omp-data/logs/5etr/080422.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");
}

Please help me, to run the above code.

Regards
# 7  
Old 04-24-2008
Anybody Please Reply !!!!!!!!

ANYBODY PLEASE REPLY !!!!!!!!


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