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

Variable question 1

Status
Not open for further replies.

jo90

Programmer
Jun 19, 2002
30
0
0
GB
Hi,

I am trying to pass the following value 01/Oct/2002:15:56:55 to a variable, however when I try to test it in my script I get the following error message....

nawk: nonterminated character class [01/Oct/2002:15:56:55

Should I convert the 01/Oct/2002:15:56:55 to string or something before doing this? If so how is this possible?

Thanks,
Jo.
 
Hi jo90,

You may have to enclose in double quotes:

nawk -v var="01/Oct/2002:15:56:55" -f awkscript.awk

You may also have to add backslashes to escape the
forward slashes:

nawk -v var="01\/Oct\/2002:15:56:55" -f awkscript.awk

One or the other should work for you.



flogrr
flogr@yahoo.com

 
flogrr,
welcome back - glad to see ya again vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
flogrr,

Thanks for your help, I've figured that much out, but what I'm trying to do is a little different & I should have elaborated.... this is my code



test = $1
print &quot;THIS IS TEST&quot; test
where = match($0, &quot;test&quot;)

It's pretty simple, but I'm assigning the variable;
01/Oct/2002:15:56:55 to test using $1, I know it's being passed to test as the

print &quot;THIS IS TEST&quot; test is printing the line, however I wish to use match using this variable again, and the match statement is returning 0.... also when I use

where = match($0, test)

I get
nawk: nonterminated character class 01/Oct/2002:15:56:55

so this is where I am stuck....
 
Jo-

O.K., this is what you need to do:

#!/bin/sh # Must be run in Bourne Shell

test=$1

When used within nawk it is addressed:

&quot;'$test'&quot; # Have to have double layer of quotes
# to protect var from interpretation
# by the shell

So, just enclose you varname in quotes as shown every
place it is used in your nawk program.

You may have to reverse the order of the quotes if using
numerical values:

'&quot;$test&quot;' # One way works for both text and numerical
# data and the other sometimes fails with
# numerical values (I can't remember which)

Try it both ways and see!

Hope this helps,


flogrr
flogr@yahoo.com

 
Hi Vlad!

Thanks for the welcome.

Since 9/11 I have been kept very busy with no sign of relief! I do check on what is going on but cannot spare the time to help out a lot.

However, you folks (Cakiwi, marsd, yourself, and others) have been dealing with some complex awk problems lately and providing great solutions for them. I commend you all!

I toss in my $0.02 worth occasionally.

Until I can contribute more, see ya!



flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top