I want to replace the column in a line with some keys in a file
for val in "${keyarr[@]}";
do
while read dataline <&3 && read keyline <&4; do
echo $dataline |
awk -F $ifs -v col=$val -v line=$keyline '{
$col=line; print $0 ;} ' OFS=$ifs > sourcedata1
done 3<sourcedata1 4<keysnotfound
done
val
is the column number that I want to replace with a key.
So I may have multiple columns to replace.
This solution does not work. how can I replace multiple columns with the keys all at once.
for example I fetch a line from sourcedata1
101, 102, 103 , 104
and from keynotfound
in the while loop
105
And at the first iteration of for loop val = 1
then I want to replace 1st column of the dataline with the key
105, 102, 103, 104
and same for the second iteration if val = 3
.
105, 102, 105, 104
Instead of using for loop, I want a solution in AWK or SED itself and it should update the source file with keys in multiple column.