Alright, it seems I cannot find a way to do what I need.Let's say I have a text file A like this(freqBiasL2[27])      (SatBiasL1[27])       (defSatBiasL2_L1[27]) (defSatBiasSlope[27]) (defSatBiasSigma[27]) (freqBiasL2[28])      (SatBiasL1[28])       (defSatBiasL2_L1[28]) (defSatBiasSlope[28]) (defSatBiasSigma[28]) (freqBiasL2[29])      (SatBiasL1[29])       (defSatBiasL2_L1[29]) (defSatBiasSlope[29]) (defSatBiasSigma[29])and so on.I want to change the index between [] brackets such that each index i is = i+3. I tried with a combination of for loop and sed, but not working for i in {27..107..1}do    i_new=$((i+3))    sed -e 's/\['$i'\]/\['$i_new'\]/' prova.txt doneThe problem is that it will change the first 27 for 30 but on next interations it will find 2 blocks with index 30 (the changed one and the original). How can I do it without overwriting the already changed indexes? Ok thanks, I edit my question for an improvement:How can I do something similar is if I have 2 indexes like:(freqBiasL2[32][100])(SatBiasL1[32][101])(defSatBiasL2_L1[32][102])(defSatBiasSlope[32][103])(defSatBiasSigma[32][104])and I want to increment only the second index ignoring the first one?
Increment index in file
linux;text processing;perl;numeric data
Use perl:perl -pe 's/(?<=\[)(\d+)(?=\])/$1+1/ge' prova.txtExplanation:-p means loop over every line and print the result after every line-e defines the expression to execute on every lines/from/to/ does a simple substitions/(\d+)/$1+1/ge matches one or more digits, captures it into $1, and then the e modifier on the end tells perl that the substition string is an expression: $1+1 substitutes the value of $1 plus 1. The g modifier means do this substitution globally, i.e. more than once per line.(?<=\[) is a positive zero-length lookbehind assertion. That means that what comes after it only matches if it's preceded by [ (which needs to be escaped with \ as [ is a special token in regular expressions). The zero-length thing means that it's not part of what will be replaced.(?=\]) is a positive zero-length lookahead assertion. That means that what comes before it only matches if it's followed by ] (again escaped).So this will take all numbers between [ and ] and increment that number.