I've tested the code you posted and it seems to work fine, so there must be something wrong with the parts you aren't showing us. If I had to guess I'd say that maybe bankFileRecord
is 0 so the body of the while loop is never executed?
Edit: I made a mistake when I ran your code myself, there was a small detail I didn't see. The problem is with your replacement string:
replacedRecord = data.gsub(/(Valore=")(.*")/i, "\\1#{indexRecord+1}")
should be changed to:
replacedRecord = data.gsub(/(Valore=")(.*")/i, "\\1#{indexRecord+1}\"")
you missed the closing speech mark. (you need to change it in both the gsubs)