Could you please try following.
Variable with values in shell:
string="file1.txt, file2.txt, file3.txt"
Creating a shell array as follows:
IFS=', ' read -r -a array <<< "$string"
OR if you want to stick with your way of defining array then do like:
array=(file1.txt file2.txt file3.txt)
Passing above shell created array to awk
and reading Input_file for doing the final operations.
awk -v arr="${array[*]}" '
BEGIN{
FS=OFS="{"
num=split(arr,array," ")
for(i=1;i<=num;i++){
sub(/\.txt/,"",array[i])
array1[array[i]"}"]
}
}
$2 in array1{
$2="a-"$2
}
1
' Input_file
Explanation: Adding explanation of above code here.
awk -v arr="${array[*]}" ' ##Creating a variable named arr whose value is all elements of array(shell array).
BEGIN{ ##Starting BEGIN section of awk code here.
FS=OFS="{" ##Setting FS and OFS as { here.
num=split(arr,array," ") ##Splitting arr variable into array named array with delimiter space and its length is stored in num variable.
for(i=1;i<=num;i++){ ##Starting for loop from i=1 to till value of variable num.
sub(/\.txt/,"",array[i]) ##Using sub to substitute .txt with NULL in array value whose index is variable named i.
array1[array[i]"}"] ##Creating an array1 whose index is array[i] value with } in it.
} ##Closing for loop here.
} ##Closing BEGIN section of code here.
$2 in array1{ ##Checking condition if $2 of current line is present in array named array1 then do following.
$2="a-"$2 ##Adding string a- with value of $2.
} ##Closing BLOCK for condition here.
1 ##Mentioning 1 will print edited/non-edited line of Input_file.
' Input_file ##Mentioning Input_file name here.