Using Variables in pattern matches 
Author Message
 Using Variables in pattern matches

I am using GNU's GAWK on a Windows NT Workstation.  I am
wondering if it possible to substitute a variable for a
regexp that I am searching for.  Here is an example of what
I would like to do.

I would like to turn

   if ($0 ~ /BR: 01/) {
   if ($0 ~ avariable) {

and then supply the value of avariable from the comand line.

I have tried the following:

  if ($0 ~ av) {
         print NR >> fname


I call this program using the following statement

gawk -fmy.awk -v av="BR: 01" -v fname="ranges.txt" r097.rpt

This does not work for me.  It does not produce any errors
it just doesn't produce any output either.  If I hard code
in the value of AV as in if ($0 ~ /BR: 01/) it works fine
and correctly uses the variable for the filename.

I am new to AWK/GAWK and feel it is just lack of knowledge
on my part.  Please forgive me if this seems like a trival
matter to more experianced users.

Thanks for your assistance


* Sent from AltaVista http://www.*-*-*.com/ Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

Sat, 20 Jul 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. using variable as a pattern for matching

2. problems pattern matching a variable

3. how to use a shell variable in awk for pattern matching

4. variables in a pattern match

5. Variable Pattern Matching

6. variable in pattern match

7. Pattern matching using "re"

8. pattern matching using regular expressions

9. can prolog be used for pattern matching?

10. returning a part of string using pattern matching

11. iss-matching - the free Regular Expression / Pattern Matching cluster


Powered by phpBB® Forum Software