Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

find and replace in vi

Posted on 2003-03-28
6
Medium Priority
?
1,209 Views
Last Modified: 2013-12-13
hello guys,
1.how to do find and replace in vi editor??
2.how to get the man page of the particular word at which the cursor is blinking (if there r any settings to do so plz mention like exrc)
0
Comment
Question by:k_kalyan
6 Comments
 

Accepted Solution

by:
chidamz earned 200 total points
ID: 8223714
Hi
 Open a file in vi editor ,after opening file
1. to find  just enter / this will lead u to the
end of window after
/[word u want to find]
for example to search kalyan in the file after u have opened
file
/kalyan

then press enter it will lead to word kalyan
if u press word N then it will go to next
kalyan in the file

2.to replace

 open file in vi editor
 type : it will lead to end of file with semicolon :

  :1,$  s/word to be replaced/word to be replaced with/g

example to replace word kalyan with chida
  :1,$ s/kalyan/chida/g

 here 1 denotes first line,$ denotes till last line
  s denotes string
   g denotes globally


E.chidambaram
0
 
LVL 18

Expert Comment

by:liddler
ID: 8223754
instead of 1,$ you can use %
i.e
:%s/kalyan/chida/g
0
 
LVL 2

Expert Comment

by:jozatan
ID: 8236614
I'll repeat some of the comments above but I'll add my own too.

1. Find: "/search_string_here" without the quotes. If you are searching for string including slash insert backslash before that. An example: if you are looking for http://blah your search string should be:

/http:\/\/blah

or like liddlet mentioned above you can use:

%http://blah

Replace: It depends what do you want to replace. I mean single string, all strings, all strings from point to another point. If you are more specific we can help you with details. For global replace of a string use:

:g/old_string/s//new_string/g

2. On the shell (prompt) you have to type:

man -k word

where the 'word' is the one you are looking for and you'll get a list of manual pages which are incuding that word. If they are too many you can use

man -k word | less

and list them with up/down arrow.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Expert Comment

by:Blixem
ID: 8246781
try this:

%s/searchstring/replacestring/gc

the gc is optional, g tells the line to keep looking globally through what you are editing instead of the line you are on. If you leave off the g it only searches the line you are on.

the c tells it to give you a confirmation or an "Are you sure ?" on every instance it finds.
0
 

Expert Comment

by:CleanupPing
ID: 9087587
k_kalyan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 2

Expert Comment

by:TheWeakestLink
ID: 9294529
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept comments from chidamz as answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheWeakestLink
EE Cleanup Volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question