Awk has a match () function which returns the extent of a match, in a form that substr() can handle. It also returns a truth condition, so it can be used as the pattern part of an awk statement to trigger the following action.

A pattern that looks like the whole word containing your token would match anything NOT a space before or after the token: /[^ ]*PR1_OWNER[^ ]*/.
"[ ]" means a space class, so "[^ ]" means the inverse - anything not a space. So "[^ ]*" means "any zero or more consecutive characters that are not spaces".

You can end and restart the single quotes that should be around your awk code. In between, you are in shell again, and can inject shell values into the line. Shell just sticks all the quoted parts together.

You can, as above, use -v. This is good for most current awks, but not for some old AIX and Solaris awks. Some old awks only accept -v with a variable whose name is all uppercase (it was meant to set OFS and OFMT and other awk built-ins originally).

But to do that, you also have to get the variable into the right place. That is easy if it is just being used as a variable, as in the print in the previous post above. But to make it part of a pattern, you are going to have to do a string concatenate in awk. Something like:

You'll have noticed I choose to keep the pattern part of the RE defined in awk. I don't want a shell variable like:
[^ ]*${Bash_Variable_Name}[^ ]*
because somebody will mis-quote it and do file expansion or shell substitution on it by mistake.

Generally, for complex problems in awk I now pass files into awk indirectly. That is, my input to awk is a Here document of commands that set internal variables, name the files, control the sequence of operations, and demand the reports.

So posting the command "file a Foo.txt" into awk makes an array ArrayA containing all the lines in the file.

It requires a fair bit of coordination between the here doc and the script design, but the result is a bunch of re-usable tested awk functions that you can stitch together into new functionality really easily.

Sorry, went a bit off-message on the previous post. This is simplified to be specific to your problem.

You can push your required variable value in on the data stream. Here are two examples. The first puts the pattern on the first line and all the data follows it. The second puts the pattern on the first line and just the filename to be processed on the second line. They are both good idioms that are applicable to much more complex awk problems. Obviously, in both cases the value of PR1_OWNER is in the scope of the shell, not inside an awk program, so you can do any shell command (like substitution) that you wish on it.