My problem is the following- I have file with SQL syntax in it. For example content of sql.txt:
select a,b from
x.tabl where A;
select b,c from x.tabl
;
select c,d from x.tabl where B;
Select d from
tabl
;
select z from x.table;
Select a,b from x.tabl_3;
Now what I want to do is to rewrite this file in bash, replacing all x.tabl and tabl with y.rtabl (new name differs only by name prefix and db).
So expected output is:
select a,b from
y.rtabl where A;
select b,c from y.rtabl
;
select c,d from y.rtabl where B;
Select d from
y.rtabl
;
select z from x.table;
Select a,b from x.tabl_3;
what I've got so far:
eval "sed -e 's/x.tabl/y.rtabl/' sql.txt>copysql.txt"
eval "mv copysql.txt sql.txt"
eval "sed -e 's/tabl/y.rtabl/' sql.txt>copysql.txt"
eval "mv copysql.txt sql.txt"
Or
eval "sed -e 's/\Wx.tabl\W/ y.rtabl /' sql.txt>copysql.txt"
eval "mv copysql.txt sql.txt"
eval "sed -e 's/\Wtabl\W/ y.rtabl /' sql.txt>copysql.txt"
eval "mv copysql.txt sql.txt"
The mv part works quite neatly for me, but sed requires some serious tuning.
mvcommand by using seds-i ''optionsed -iis an inexplicable, non-standard extension to do whatedalready does.