You will have great difficulty creating regexp's in this manner.
Better is to do something like:
function is_match(str,list, arr,a,x) {
#splitlist based on whitespace,breaks if whitespace in passed args
a = split(list,arr)
if (a) {
#iterate through all elements
for (x =1 ; x <= a ; x++) {
print "Matching against:", arr[x], "and", str
#match against each element
if (str ~ arr[x]) {
#return positive for a match
return 1
}
}
}
return 0
}
BEGIN {
#iterate through passed arguments
for (i=1 ; i <= ARGC ; i++) {
if (ARGV
== "-x"
{
#build our restricted list by choosing "-x" + 1 in the array and concatenating with a whitespace sep.
restrict = length(restrict) < 1 ? ARGV[i + 1] :
restrict" "ARGV[i + 1]
}
if (ARGV == "-t"
{
#as above, for the excepted list
except = length(except) < 1 ? ARGV[i + 1] :
except" "ARGV[i + 1]
}
}
#verbose check
print "RESTRICTED: ",restrict, "EXCEPTED: ", except
#awk will complain and fail if you pass params as you
#try to main(). Instead all processing can be done here.
while ((getline < ARGV[ARGC - 1]) > 0) {
all_recs[p++] = $0
#load all lines in filename(last argument) - 1 toarray all_recs
}
close(ARGV[ARGC - 1])
#iterate through the array records matching against
#all records and expressions,actions are in the if blocks.
while(++t < p) {
if (is_match(all_recs[t],restrict)) {
input_str=""
print "Restrict match"
}
if (is_match(all_recs[t],except)) {
print "Except match"
}
}
}
Now you can call the program like:
awk -f awkprog -t "trueandfalse" -x "Thisisnottrue" -x "false" -x "notfalse" -t "truefalseandfalse" scrap.txt
SAMPLE OP:
Matching against: Thisisnottrue and "CAMEL_MODIFICATION" = "5F"
Matching against: false and "CAMEL_MODIFICATION" = "5F"
Matching against: notfalse and "CAMEL_MODIFICATION" = "5F"
Matching against: trueandfalse and "CAMEL_MODIFICATION" = "5F"
Matching against: truefalseandfalse and "CAMEL_MODIFICATION" = "5F"
Matching against: Thisisnottrue and "INTERNAL_CAUSE_AND_LOC" = "0003"
Matching against: false and "INTERNAL_CAUSE_AND_LOC" = "0003"
Matching against: notfalse and "INTERNAL_CAUSE_AND_LOC" = "0003"
Matching against: trueandfalse and "INTERNAL_CAUSE_AND_LOC" = "0003"
Matching against: truefalseandfalse and "INTERNAL_CAUSE_AND_LOC" = "0003"
, etc...