I am new to awk, so please excuse any mistakes.
I was hoping someone would be able to tell me if it's possible to include variables in a regular expression, and if so, how.
The code I currently have is the find the beginning of link (<a) and image (<img) tags in an html page.
Instead of duplicating this same code for each tag (ie, hard code each value in), I was hoping to be able to use a for() loop to loop over the same expressions, simply changing the variable each loop.
The code I have:
setTags[1,1] = "<a"
setTags[2,1] = "<img"
for ( j = 1; j < 3; j++ ) {
TAG = setTags[start,1]
split($0,removeFront,/[>]?[.*]?TAG/)
}
This loops through twice, once looking to split by a link tag, and another to split by the image tag. This will tell me how many links and how many images are on each line.
However, I am unable to get the TAG variable (only uppercase to make it stand out) interpreted. Depending on what I do, it will look for the letters T, A and G, or it simply won't work.
Any assistance you can give would be greatly appreciated.
Thanks,
Ralf