I recall reading somewhere that when you use a variable in a test, the contents of it are treated as a regex, meaning you should store the entire pattern in the variable and leave the /../ brackets off. I can't locate any clear statement for it in the gawk manual, but it does appear to be true in testing:
Code:
$ x=78 Code:
$ awk -v y="^$x" 'y { print }' file.txt Code:
$ awk -v y="\\\y$x\\\y" '$0 ~ y {print}' file.txt Code:
$ mawk -v y="(^$x|$x$|[ \t]$x[ \t])" '$0 ~ y { print }' file.txt |
Ok. This is a mawk problem, since word boundaries are a GNU awk (gawk) extension. You can try something different, like:
Code:
awk '/[^0-9]'$x'[^0-9]/' FILE Code:
awk '/[^[:alnum:]]'$x'[^[:alnum:]]/' FILE |
Well the first suggestion I would have is to remove mawk and install gawk. It sounds harsh but mawk has a number of limitations that i have run into (not really sure why it was created actually).
All of colucix's suggestions are good and can be used with a variable and computed regex as well (at least I hope so) |
I'm not getting any output with character classes in mawk. The same patterns do work in gawk and nawk, so it looks like mawk just doesn't support them either.
|
Quote:
Code:
$ mawk '/[^[:alnum:]]'$x'[^[:alnum:]]/' testfile |
Hmm. Version listed as 1.3.3 here. The exact same command and data isn't giving me anything. Again, nawk and gawk do just fine.
The release page does say that some unspecified "improvements" to the regex engine were added recently. http://freshmeat.net/projects/mawk/releases Debian's always behind the times. :( |
All times are GMT -5. The time now is 01:00 AM. |