I have a script which will mask the 9th and 15th column in a record starting with BPR.
The record looks like below before my script
BPR*C*160860.04*C*ACH*CTX*01*072000326*DA*1548843*3006968523**01*071000013*DA*5529085*100323*VEN
The record will be masked after my script parses this record
BPR*C*160860.04*C*ACH*CTX*01*072000326*DA*XXX8843*3006968523**01*071000013*DA*XXX9085*100323*VEN*
I do not want the '*' character at the end of the record at any point.
Below is my script
function chgrec(rec){
debug=1
z=split(rec,rarray,"*")
element=10
unChanged = rarray[element]
lUnChg = length(unChanged)-3
lastFour = substr(unChanged,lUnChg)
initValue = rarray[element]
gsub(/[0-9A-Za-z]/,"X",initValue)
preFix = substr(initValue,1,lUnChg-1)
element2=16
unChanged2 = rarray[element2]
lUnChg2 = length(unChanged2)-3
lastFour2 = substr(unChanged2,lUnChg2)
initValue2 = rarray[element2]
gsub(/[0-9A-Za-z]/,"X",initValue2)
preFix2 = substr(initValue2,1,lUnChg2-1)
rec=""
for (i=1;i<=z;i++){
# printf("-->1:%s-->2:%s\n", i, rarray)> "/tmp/fftt";
if (debug=0)
{
if (i==element)
rec=rec sprintf("-->%s%s<--(%s)*", preFix, lastFour,rarray[element])
else
if (i==element2)
rec=rec sprintf("-->%s%s<--(%s)*", preFix2, lastFour2,rarray[element2])
else
if (i==z)
rec=rec sprintf("%s*", rarray)
}
else
{
if (i==element)
rec=rec sprintf("%s%s*", preFix, lastFour,rarray[element])
else
if (i==element2)
rec=rec sprintf("%s%s*", preFix2, lastFour2,rarray[element2])
else
rec=rec sprintf("%s*", rarray)
}
}