I have spent hours on Awk tutorials but I can not get around that one: I want to use a variable as a regex for a awk query. Here is an example of what i want to achieve:
#!/bin/bash
#My test array
testarray=(teststring[1078] teststringthatshouldnotmatch teststring[5845])
#myregex as a variable
regex="teststring\[.*"
#the awk
for value in ${testarray[*]}
do
echo ${value} | awk '{if ($1 ~ regex) print}'
done
I woud expect Awk to match teststring 1 and 3 but it matches all. Thanks for any light on this one.