The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to access values of awk/nawk variables outside the awk/nawk block? saniya Shell Programming and Scripting 5 05-13-2008 07:37 AM
Passing Vars between scripts rcunn87 Shell Programming and Scripting 4 06-23-2006 06:07 AM
Can I export vars without polluting my namespace? tphyahoo Shell Programming and Scripting 2 06-06-2006 11:03 AM
Env vars in a SED script Bags Shell Programming and Scripting 8 05-12-2006 02:53 PM
need help with nawk using -v vars amon Shell Programming and Scripting 3 01-26-2006 06:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2008
wakhan wakhan is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 58
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 04:19 AM.. Reason: added code tags
  #2 (permalink)  
Old 04-21-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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 08:08 AM.. Reason: remove cat command
  #3 (permalink)  
Old 04-21-2008
wakhan wakhan is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 58
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 (permalink)  
Old 04-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Where is the cat command for?

Regards
  #5 (permalink)  
Old 04-21-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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 (permalink)  
Old 04-23-2008
wakhan wakhan is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 58
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 (permalink)  
Old 04-24-2008
wakhan wakhan is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 58
Anybody Please Reply !!!!!!!!

ANYBODY PLEASE REPLY !!!!!!!!


Regards,
Waqas Ahmed
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0