Substitute Command in vi | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Substitute Command in vi

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-10-2005
lesstjm lesstjm is offline
Registered User
 
Join Date: Nov 2001
Last Activity: 19 February 2010, 7:24 AM EST
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Substitute Command in vi

How do I substitute a word throughout a file? For example change all instances of the word John to Mark. This would be in vi for korn shell.
Sponsored Links
    #2  
Old 03-10-2005
reborg's Avatar
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 10 Times in 10 Posts
command mode:

:1,$s/WORD_TO_REPLACE/WORD_TO_SUBSTITUTE/g
Sponsored Links
    #3  
Old 03-10-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 26 July 2012, 3:38 PM EDT
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
or

:%s/John/Mark/g
    #4  
Old 03-26-2005
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
 
Join Date: Aug 2001
Last Activity: 18 April 2013, 3:03 PM EDT
Location: San Antonio, TX,
Posts: 1,070
Thanks: 0
Thanked 4 Times in 4 Posts
Or

:g /John/s//Mark/g


OR From outside the file...

# cat file.in | sed 's/John/Mark/g' > file.out
Sponsored Links
    #5  
Old 03-26-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 19 April 2014, 1:25 PM EDT
Location: Foxborough, MA
Posts: 7,527
Thanks: 137
Thanked 534 Times in 502 Posts
Quote:
Originally Posted by Kelam_Magnus
Or
OR From outside the file...

# cat file.in | sed 's/John/Mark/g' > file.out
UUOC

sed 's/John/Mark/g' file.in > file.out
Sponsored Links
    #6  
Old 03-26-2005
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
 
Join Date: Aug 2001
Last Activity: 18 April 2013, 3:03 PM EDT
Location: San Antonio, TX,
Posts: 1,070
Thanks: 0
Thanked 4 Times in 4 Posts
yea, I was just showing all known uses....

grep <pattern> file.in | sed 's/John/Mark/g' > file.out
Sponsored Links
    #7  
Old 03-26-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 26 July 2012, 3:38 PM EDT
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by Kelam_Magnus
yea, I was just showing all known uses....

grep <pattern> file.in | sed 's/John/Mark/g' > file.out

That will filter out other lines in file.in ; Right ??
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Substitute in VI brian112 UNIX for Dummies Questions & Answers 3 02-14-2012 11:19 AM
substitute the starting dollar sign in command with blank swethakast Shell Programming and Scripting 2 03-22-2011 06:53 AM
howto substitute word in vi command mode presul Shell Programming and Scripting 9 06-13-2010 08:21 AM
How to substitute? vanitham Shell Programming and Scripting 2 12-14-2008 11:12 PM
how to write perl substitute command in shell scripts param_it UNIX for Dummies Questions & Answers 3 07-03-2007 04:09 AM



All times are GMT -4. The time now is 01:34 PM.