Не могли бы вы попробовать следующее, это в форме сценария оболочки, который нужно запустить, предоставив аргументы сценарию (протестировано и написано с показанными образцами).
cat script.ksh
val="$@"
awk -v arg="$val" '
BEGIN{
FS="="
num=split(arg,array," ")
for(i=1;i<=num;i++){
array1[array[i]]
}
}
/group/{
if(sum==num){
print group_value
}
sum=""
gsub(/[^0-9]*/,"")
group_value=$0
next
}
($NF in array1){
sum++
}
END{
if(sum==num){
print group_value
}
}
' Input_file
Когда я запускаю его следующим образом:
./script.ksh xyz xyy zyx
3
Объяснение: Добавление подробного объяснения приведенного выше кода здесь.
cat script.ksh
val="$@" ##Creating a shell variable named val which has all values of arguments passed to script.
awk -v arg="$val" ' ##Starting an awk program from here and creating a variable arg whose value is shell variable val here.
BEGIN{ ##Starting BEGIN section from here.
FS="=" ##Setting FS as = here.
num=split(arg,array," ") ##Splitting arg variable into an array with delimiter as space here.
for(i=1;i<=num;i++){ ##Running for loop from i=1 to till value of num here.
array1[array[i]] ##Creating an array named array1 with index of value of array with index i here.
}
}
/group/{ ##Checking condition if line contains group string then do following.
if(sum==num){ ##Checking condition if sum==num then do following.
print group_value ##Printing variable group_value here.
}
sum="" ##Nullifying variable sum here.
gsub(/[^0-9]*/,"") ##Globally substituting everything apart from digits with NULL here in current line.
group_value=$0 ##Setting variable group_value value to current line value here.
next ##next will skip all further statements from here.
}
($NF in array1){ ##Checking condition if last field of current line is present in array1 then do following.
sum++ ##Increase count of sum variable with 1 here.
}
END{ ##Starting END block for this code here.
if(sum==num){ ##Checking condition if sum==num then do following.
print group_value ##Printing variable group_value here.
}
}
' Input_file ##Mentioning Input_file name here.