How To Search And Replace Text With Linux VI Editor
Posted On Thu Sep 04, 2008 By hostman In Linux wallpaper Hosting forums topics about gallery sites in linux systems Forums
ok, if you are wanting to know how you can find and replace text in a file in linux you are in luck, i will show you how..
lets say i have a file called wallpaperama.txt and this is what the files has:
Wallpaperama is an amazing collection of high resolution quality free wallpapers.
you can download your favorite wallpaper for free.
tell your friends about walllpaperama
you can vote for your favorite wallpaper
surf with confidence, all our wallpaper dont have spyware.
we hate spam, so we wouldn't give you that either.
we hope you enjoy our beautiful wallpapers
ok, on the example text file above, lets say i want to change all the 'wallpaper' to 'screensaver' well this is how you would do it..
lets assume that wallpaperama.txt is located on my home directory at: /home/me/wallpaperama.txt
step 1. open the file with the vi editor:
step 2. Enter - SHIFT + : (the Shift key and the colon key at the same time) on your keyboard, the screen will look like this:

step 3. now enter this command and hit enter
step 4. now you will see that all the text 'wallpaper' was changed to 'screensaver'

step 5. save the change with this command:
DONE
i hope this helps you
lets say i have a file called wallpaperama.txt and this is what the files has:
Wallpaperama is an amazing collection of high resolution quality free wallpapers.
you can download your favorite wallpaper for free.
tell your friends about walllpaperama
you can vote for your favorite wallpaper
surf with confidence, all our wallpaper dont have spyware.
we hate spam, so we wouldn't give you that either.
we hope you enjoy our beautiful wallpapers
ok, on the example text file above, lets say i want to change all the 'wallpaper' to 'screensaver' well this is how you would do it..
lets assume that wallpaperama.txt is located on my home directory at: /home/me/wallpaperama.txt
step 1. open the file with the vi editor:
vi /home/me/wallpaperama.txt
step 2. Enter - SHIFT + : (the Shift key and the colon key at the same time) on your keyboard, the screen will look like this:

step 3. now enter this command and hit enter
:%s/wallpaper/screensaver/g
step 4. now you will see that all the text 'wallpaper' was changed to 'screensaver'

step 5. save the change with this command:
:qw
DONE
i hope this helps you
OptimusPrime Sun Feb 26, 2012
Dude, whats is the meaning of %? and s= search? I'm newbie at linux...
moster Thu Sep 04, 2008
this might help you also:
Vi: Search and Replace
Change to normal mode with <ESC>.
Search (Wraped around at end of file):
Search STRING forward : / STRING.
Search STRING backward: ? STRING.
Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)
Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
Vi: Search and Replace
Change to normal mode with <ESC>.
Search (Wraped around at end of file):
Search STRING forward : / STRING.
Search STRING backward: ? STRING.
Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)
Replace: Same as with sed, Replace OLD with NEW:
First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
Related Content
Information
Forums »
Linux wallpaper Hosting forums topics about gallery sites in linux systems »
How To Search And Replace Text With Linux VI Editor
Linux wallpaper Hosting forums topics about gallery sites in linux systems »
How To Search And Replace Text With Linux VI Editor
Title: How To Search And Replace Text With Linux VI Editor
Description: How To Search And Replace Text With Linux VI Editor
Tags: how ,to ,search ,and ,replace ,text ,with ,linux ,vi ,editor
Info: This Post Has Been Viewed 0 Times Since
Date: Thu Sep 04, 2008
Author hostman Received 3 Replies #519
Date: Thu Sep 04, 2008
Author hostman Received 3 Replies #519
Share
URL: 

Embed: 

To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it
BBCODE:: 

BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
wallpaperama | Wallpapers | Forums | Terms Of Service
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5