I am using gvim on windows and have a file with several lines that look like this
Select '305','TableA Select '313','TableB Select '313','TableC I would like to append the following line at the end of each line.
', count(*) from [Tablename] where msgid in (select msgid from mainTable where row_dtm<'17NOV11') The result should look something like this (Note that the [TableName] is replaced by the actual table name.
Select '305','TableA', count(*) from TableA where msgid in (select msgid from mainTable where row_dtm<'17NOV11') Select '313','TableB', count(*) from TableB where msgid in (select msgid from mainTable where row_dtm<'17NOV11') Select '313','TableC', count(*) from TableC where msgid in (select msgid from mainTable where row_dtm<'17NOV11') I can add append the text at the end by just doing
%s/$/', count(*) from [Tablename] where msgid in (select msgid from mainTable where row_dtm<'17NOV11')/g But i am stuck as to how i can read the table name and put that in place of [Tablename].
Basically i am just trying to generate several queries. Any ideas? I know that the table name will always be the text from the end of the line to the first ' character but how do i read it and add it to the modified string?
Thanks