Insert a single quote in front of a line in vi editor

Hello Gurus,
I wanted to put a single quote in every where starting with /oradata, and at the end with .dbf.

For example I have one line as below:

alter database rename datafile /oradata/test.dbf to /oradata_new/test.dbf 

I wanted as below

alter database rename datafile '/oradata/test.dbf' to '/oradata_new/test.dbf'

Please advice.

Thanks-
Pokhraj

Hello Pokhraj,

Following may help you in same, if you want to change the source file itself.

awk -vs1="'" '{$5=s1 $5 s1;$NF=s1 $NF s1;} 1' Input_file > temp_Input_file
mv temp_Input_file Input_file

If you don't want to change the source(Input_file) then remove move command from solution.

EDIT: You can do following in vi editor.
The formal syntax for searching is:

:s/string

For example, suppose you want to search some text for the string "cherry." Type the following and press ENTER:

:s/cherry

The first match for "cherry" in your text will then be highlighted. To see if there are additional occurrences of the same string in the text, type n, and the highlight will switch to the next match, if one exists.

The syntax for replacing one string with another string in the current line is

:s/pattern/replace/

Here "pattern" represents the old string and "replace" represents the new string. For example, to replace each occurrence of the word "lemon" in a line with "orange," type:

:s/lemon/orange/

The syntax for replacing every occurrence of a string in the entire text is similar. The only difference is the addition of a "%" in front of the "s":

:%s/pattern/replace/

Thus repeating the previous example for the entire text instead of just for a single line would be:

:%s/lemon/orange/

Thanks,
R. Singh

Try also

awk '{gsub(/\/oradata[^ ]*dbf/,"\047&\047")}1' file
alter database rename datafile '/oradata/test.dbf' to '/oradata_new/test.dbf'

With sed:

sed "s|/oradata[^ ]*\.dbf|'&'|g" file