Hello all.
I am an absolute beginner in awk.
I have an awk script which look into a text file to find if and where some commands are present.
I put the name of the command I look for in an awk user variable, let's name that variable thecommand.
How to write a regex to find the absolute path of thecommand if mentioned in the text file?
Let's say if I look into the third field of each record, for instance. This doesn't work:
Code:
$3 ~ /^\/(.+\/)*thecommand/
Should I quote thecommand in some way, or what?
Or how can I extract the last word from the path, to be able to compare it with thecommand?
EDIT. I found a solution (not including the variable's name in the regex but checking that it's the last word of the path):
Code:
$3 ~ /^\/(.+\/)*.*/ && length(thecommand) + index($3,thecommand) == length($3)+1
PS Still, I would be interested to know how to include a variable's name in a regex...