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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 03-10-2005
reborg's Unix or Linux Image
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 11 Times in 11 Posts
command mode:

:1,$s/WORD_TO_REPLACE/WORD_TO_SUBSTITUTE/g
Sponsored Links
    #3  
Old Unix and Linux 03-10-2005
bhargav's Unix or Linux Image
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 Unix and Linux 03-26-2005
Kelam_Magnus's Unix or Linux Image
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 5 Times in 5 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 Unix and Linux 03-26-2005
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 March 2015, 10:08 AM EDT
Location: Foxborough, MA
Posts: 7,764
Thanks: 170
Thanked 633 Times in 591 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 Unix and Linux 03-26-2005
Kelam_Magnus's Unix or Linux Image
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 5 Times in 5 Posts
yea, I was just showing all known uses....

grep <pattern> file.in | sed 's/John/Mark/g' > file.out
Sponsored Links
    #7  
Old Unix and Linux 03-26-2005
bhargav's Unix or Linux Image
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 02:07 AM.