Hi I want to replace only the last occurance of "union all" in input file with ";"
I tried with sed 's/union all/;/g' in my input file, it replaced in all lines of input file
Eg:
select column1,column2 from test1 group by 2 union all
select column1,column2 from test2 group by 2 union all
select column1,column2 from test3 group by 2 union all
I need to replace only the last "union all" in the above with ";".
Does Centos have the ex utility? If so, for the features I used in the ed script in post #3, ex will work the same way with the same options. On UNIX, Linux, and BSD systems, I usually use ed instead of ex because ex is usually larger and slower to load than ed . The ex utility is bigger because it supplies some extra features that ed doesn't provide, but they aren't used in this script.
where 3 is the line number. This is useful if you know which line to target at, while the grep command will search for all the lines containing the matched pattern(s).
Hope that this is useful.
Cheers.
EDIT:
Just realised that I did not really solve the problem of find and replace "the last occurrence of a match". But hope that my approach can cast a different light on the approaches used to solve your problem.