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;

Saturday, September 13, 2014

How to Change Your Command Prompt in UNIX or Linux

If you do not like your command prompt in UNIX or Linux, you can change it with the export PS1= command. In the example below, I started off with a command prompt of UBUNTU > :

UBUNTU > 

... then I changed it to show the name of the directory I was in. Here is one way to do this:

UBUNTU > export PS1='`pwd` > '
/home/andrew > cd Java
/home/andrew/Java > cd /
/ >

... and here is another:

/ > export PS1='$PWD > '
/ > cd
/home/andrew > cd Java
/home/andrew/Java > 

Finally, I changed it to say Andrew's PC: 

/home/andrew/Java > export PS1="Andrew's PC: "
Andrew's PC: