My problem is to search all expressions in a file containing: (Scenario in converting from fortran to C)
Arr1 = Arr2[4:10]
and replace with
for(i = 0 ;i < 6; i++) Arr1[ i ] = Arr2[ i+3 ]
//comment i + 3 because i + "4-1". i< 6 because 6 = "10 - 4"
I tried this in vi but this is not working:
:%s/(\<\w+>)\s+=\s+(\<\w+>)[([0-9]):([0-9])]/\='for(i=0;i<'.(submatch(4) - submatch(3)).' ;i++) \1[i] = \2[i+'.(submatc h(3) - 1).']'/gc
Kindly help. The names of arrays used in file are not same. The array indices are not same for all arrays too. Hope the question is clear. I tried using \=
and submatch()
as in another answer but, that is not allowing separate strings containing arithmetic evaluation expressions to be concatenated. I am missing something.
;
to the end of the line. Finally do you really intend to usevi
or can you usevim
?