How to replace words using VI editor on the fly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace words using VI editor on the fly
# 1  
Old 10-18-2010
How to replace words using VI editor on the fly

HI Guys,

How Can I replace particular words in a file starting from the line where my cursor is pointing while the file is opened in VI editor?

If you are using sed, please give me the code.


Thanks
# 2  
Old 10-18-2010
press escape to switch in command mode then

Code:
:45,66s/toto/titi/g

will replace toto by titi from line 45 to line 66
g = in a global manner (if toto appear more than once in a line, it get also replaced by titi)

to replace in a whole file use % :
to ask confirmation before replacement, use c , see below

Code:
:%s/toto/titi/gc

then

Code:
:wq!

... in order to save your modifications
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 10-18-2010
_TYVM_
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find replace text in xml file on the fly

Dear Unix guru, I have a .XML file which is being used to load data to oracle. This file comes on unix box and one of the tag in xml is oracle key word. I want to find that tag and replace with new tag on the fly For example I will get one of the tag in xml is as below <from>Test Test... (12 Replies)
Discussion started by: guddu_12
12 Replies

2. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

3. Shell Programming and Scripting

How to replace words in file?

Hi Guys, I have a text where we used Ram in 10 times now I want replace all Ram words by Shyam word then how to do it. (6 Replies)
Discussion started by: aaditya321
6 Replies

4. UNIX for Dummies Questions & Answers

Replace the words in the file to the words that user type?

Hello, I would like to change my setting in a file to the setting that user input. For example, by default it is ONBOOT=ON When user key in "YES", it would be ONBOOT=YES -------------- This code only adds in the entire user input, but didn't replace it. How do i go about... (5 Replies)
Discussion started by: malfolozy
5 Replies

5. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

6. Shell Programming and Scripting

In vi editor I want to replace next line char by space

in vi editor I want to replace next line char by space help me eg: input: 123 123 123 output: 123 123 123 (5 Replies)
Discussion started by: RahulJoshi
5 Replies

7. Shell Programming and Scripting

Find and replace pattern in VI editor

All, I have a text file which has the following data X_SQL_13,X_SQL_14,X_SQL_15,X_SQL_16,X_SQL_17,X_SQL_18,X_SQL_19,X_SQL_20,X_SQL_21,X_SQL_22,X_SQL_23,X_SQL_24,X_SQL_25,X_SQL_26,X_SQL_27,... (4 Replies)
Discussion started by: thana
4 Replies

8. Shell Programming and Scripting

want to replace some words with other from a list

I have a list file, in which both the words to be replaced and to be replaced with are there... need to run a script which will accept the list name and replace all the occurances .. ex. the list file contains something like hi=bye go=come Now i want to replace the words hi with bye and go... (3 Replies)
Discussion started by: dixitked
3 Replies

9. HP-UX

Replace $ sign within a file using Vi editor

Can someone help me with this command? I want to replace amount fields which are in the format $99.99 to 99.99 in a large data file which is within a HP box. I use Vi editor and tried this command :1,$s//$///g And this does not seem to work Also, I want to replace ^M with spaces in the... (1 Reply)
Discussion started by: dtonse
1 Replies

10. UNIX for Dummies Questions & Answers

globle replace comand in VI editor

Folks, How can I do a globe search & replace in VI editor? Any help? Thanks. (2 Replies)
Discussion started by: ting123
2 Replies
Login or Register to Ask a Question