Quote:
It works but, if one of the columns before the 6th column includes the number 1 then it too is renumbered. I only need $i=splitline [5] =1 ... Is it possible to move the splitLine designators outside of the foreach?
There is actually no check for the number "1" anywhere in the script. The "foreach" just iterates over all of the lines of the file, in order. The "if" statement checks to see if the line begins with "TER". If so, then the value of i is incremented, and the line is left unchanged and printed to the output. If not, then the line is split into an array of strings using the space character. The 6th element in the array is replaced with the current value of i. Then the array of strings is joined together with a space character into a single string, which is what is printed to the output.
Maybe there is some extra space on some lines which is moving the position of the column over by one? If so, maybe you could split on multiple spaces "/ +/" instead of just the single space in the current split call, but keep in mind when when you rejoin the line, if there were multiple spaces in the original data line, they would be replaced by a single space in the output.