is it possible to pass external variable values to nawk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting is it possible to pass external variable values to nawk?
# 1  
Old 02-02-2006
is it possible to pass external variable values to nawk?

Dear friends,
please tell me how to pass the external variable values to the nawk command.

length=`expr $len2 - $len1`

i need to pass $length to following nawk command as mentioned below.

nawk '{if((x=index($0,"W/X"))>0){id=substr($0,x, $length);print x;print id;}}' filename1

but I am getting follwing error,
nawk: illegal field $()
input record number 1, file filename1
source line number 1

please tell me how to pass the $length value to the nawk .


waiting for ur reeply....

swamymns
# 2  
Old 02-02-2006
here is a simple example :

$ nawk '{ print lngth }' lngth="5" file1
5
5
5
5
5
5

you can assign the shell variable nawk variable and then use the nawk variable inside the nawk script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to pass shell arguments into Nawk/awk

Hi, I am in critical need of help, Thanks a ton for your help. I need to know how to pass the shell argument into nawk code in AIX. so that my file gets passed into that awk script and it can execute it part. To be detail, i have more than 100 files and in those files a particular field... (6 Replies)
Discussion started by: Selva_2507
6 Replies

2. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

3. Shell Programming and Scripting

Pass parameter to nawk from shell script

I need to parse log files using nawk, but I'm not able to pass script input argument (date) to nawk, for example: ------------ #!/bin/ksh read date nawk -F, '{if($1==date) print $4" "$5}' ------------- Is there a way to pass an argument to nawk from shell script. Many thanks... (8 Replies)
Discussion started by: samer.odeh
8 Replies

4. Shell Programming and Scripting

Help nawk change external variable

Hello, I have external variable rownumber, I am processing files within a loop and I would like to keep incrementing rownumber. What is happening is inside nawk section it passes rownumber but it never gets updated. I want to update rownumber inside the nawk, I would appreciate your help ... (6 Replies)
Discussion started by: srattani
6 Replies

5. Shell Programming and Scripting

How to Read different values from external file?

Hi , I am new to this scripting , I am facing an issue like how to read different values from external file by using different variables, In script I supposed to declare var 1 var 2 var 3 I know how to call this variables from external file (I am using awk command by giving same... (3 Replies)
Discussion started by: chandini
3 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. UNIX for Dummies Questions & Answers

AWK (NAWK) and filtering values

Hi , i try to filter input file : 17/04/2008 06:17:09 17/04/2008 00:00:02 keeping lines with hour > 06 as : 17/04/2008 06:17:09 i tried : CSL=06 nawk -v CSL="${CSL}" -F'' '/^\[/ { if ( $4 -gt $CSL) print $0 } ; /^\>/ { if ( $5 -gt $CSL) print $0 }' input_file.txt... (11 Replies)
Discussion started by: Nicol
11 Replies

8. Shell Programming and Scripting

I can't seem to pass variables properly into a nawk statement

Ok, So up front I'm going to say that I'm a very elementary scripter, and I tend to use tools I don't fully understand, but I shotgun at something until I can get it to work...that said, I can't for the life of me understand why I can't get this to go down the way I want it to. The goal: -to... (6 Replies)
Discussion started by: DeCoTwc
6 Replies

9. Shell Programming and Scripting

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies

10. Solaris

awk/nawk returning decimal values?

Hi Running a specific nawk statement over a 17m lines files returns the following: /bin/nawk: not enough args in ..... input record number 1,25955e+06, file test.1 source line number 1 I'd like to report the line number (in bold above) in decimal not floating so that i can spot it out. ... (1 Reply)
Discussion started by: moutaye
1 Replies
Login or Register to Ask a Question