Thanks for answering my previous question. Could you please explain the highlighted code?
awk -v pos='9 27 39 54 59 64 71 78 83 103 108' 'BEGIN{split(pos,var)} {for (i in var) $0=gensub(/./,"|",var)} 1' test.txt | head
I understood that the split function splits the pos string into an array but I am confused on the usage of gensub function, especially var[i]. It wold be helpful if there is any tool which I use to visualize the steps.
You are right - the pos variable is split into the var array. Then, in all input lines ( $0 ), gensub (a specific gawk function) replaces the characters (no matter what they are!) at the positions in var by the pipe symbol, as said in man gawk :