Friday, July 24, 2015

How to Add Text at the End of Every Line in vi

I received a file of SQL statements from a 3rd party but they arrived without a semi-colon at the end of each line so I could not run them. Here are the first few (there were nearly 10,000 in all):

delete from crm7.UDEFFIELD where UDEFFIELD_Id = 10043
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 14606
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2278
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2631
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2515
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2259
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 12327
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2142
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 11344
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 10339

I used vi to add them as follows:
 
(1)          I pressed the Esc key.
(2)          I typed the following command: :%s/$/;/
(3)          I pressed Return.
 
This appended a semi-colon at the end of every line:

delete from crm7.UDEFFIELD where UDEFFIELD_Id = 10043;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 14606;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2278;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2631;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2515;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2259;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 12327;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 2142;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 11344;
delete from crm7.UDEFFIELD where UDEFFIELD_Id = 10339;

No comments:

Post a Comment