[SOLVED] Select exact regex with awk
by Drosera_capensis from LinuxQuestions.org on (#5A9WN)
Hello everyone,
I would like to use awk to select an exact regex (pattern) in a file, and print the line including the regex.
Unfortunately, as the regex is a variable "$f", I can't use the following expression:
Quote:
I have found this form of awk to pass the variable argument "$f" to awk:
Quote:
But it is not selecting the exact regex pattern.
Would anyone know how to select the exact pattern?


I would like to use awk to select an exact regex (pattern) in a file, and print the line including the regex.
Unfortunately, as the regex is a variable "$f", I can't use the following expression:
Quote:
/regex/{print} file |
Quote:
awk -v regex="$f" '$0 ~ regex {print}' file |
Would anyone know how to select the exact pattern?