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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert a single quote in front of a line in vi editor
# 1  
Old 09-05-2015
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:
Code:
alter database rename datafile /oradata/test.dbf to /oradata_new/test.dbf

I wanted as below
Code:
alter database rename datafile '/oradata/test.dbf' to '/oradata_new/test.dbf'

Please advice.

Thanks-
Pokhraj
# 2  
Old 09-05-2015
Hello Pokhraj,

Following may help you in same, if you want to change the source file itself.
Code:
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 vieditor.
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

Last edited by RavinderSingh13; 09-05-2015 at 04:55 AM.. Reason: Added examples for vi editor
# 3  
Old 09-05-2015
Try also
Code:
awk '{gsub(/\/oradata[^ ]*dbf/,"\047&\047")}1' file
alter database rename datafile '/oradata/test.dbf' to '/oradata_new/test.dbf'

# 4  
Old 09-05-2015
With sed:
Code:
sed "s|/oradata[^ ]*\.dbf|'&'|g" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[sed]: syntax to insert N spaces in front of a string

Dear all, I would like to insert N blankspaces in front of a string using sed command To give an example (N=10), I tried that code: $ echo "abcd" | sed 's/^/ \{10,\}&/' but I failed, by obtaining that result: {10,}abcd Any help would be greatly appreciated, Thanks in advance,... (18 Replies)
Discussion started by: dae
18 Replies

2. Shell Programming and Scripting

Insert single quote on every word separated by comma

Hello, I have a text file as:-ABC BCD CDF DEF EFGI need to convert as 'ABC', 'BCD', 'CDF', 'DEF', 'EFG' using a unix command anybody can help me out on this. Regards, Jas Please wrap all code, files, input & output/errors in CODE tags. It makes them easier to read and preserves... (12 Replies)
Discussion started by: jassi10781
12 Replies

3. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

4. UNIX for Dummies Questions & Answers

Insert single quote and commas

Hi All, I have a set of data as below : XS012371378 Raj 23-09-12 SH128238948 Andrew 24-08-12 CH273712399 Walsh 12-10-12 JK7249923893 Nick 10-02-13 JP6383791389 Braslin 30-12-13 I want the first column to be extracted separately. I can get this using awk. awk '{print $1}' file_name ... (3 Replies)
Discussion started by: Nand Kishor
3 Replies

5. Shell Programming and Scripting

How to insert a single quote to each record

I have a file as: 1 New used 1 used New I need o/p as: '1' 'New' 'used' '1' 'used' 'New' (12 Replies)
Discussion started by: karumudi7
12 Replies

6. Shell Programming and Scripting

how to add single digit in front of the word and line in the file.

Hi , how to add the single digit to front of the word and front of the lines in the one file with compare pattern file and get digit. like example pattern file pattern.txt pattern num bala 2 raja 3 muthu 4 File Name: chennai.dat muthu is good boy raja is bad boy selvam in super... (6 Replies)
Discussion started by: krbala1985
6 Replies

7. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

8. Shell Programming and Scripting

insert predefine text in front and on a loop

Hi Experts, I wish to insert predefined text in front of every line and this needs to be in a loop because it is always expanding. Before : 11111111 22222222 33333333 44444444 55555555 77777777 88888888 00000000 To be Inserted : a= b= (2 Replies)
Discussion started by: masayangbata
2 Replies

9. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

10. Shell Programming and Scripting

single quote

Hi I have a shell script with many lines as below: comment on column dcases.proj_seq_num is dcases_1sq; .... .... I want the above script to be as below: comment on column dcases.proj_seq_num is 'dcases_1sq'; I want to have single quotes like that as above for the entire shell... (2 Replies)
Discussion started by: dreams5617
2 Replies
Login or Register to Ask a Question