The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Substitute Variable mmg2711 UNIX for Dummies Questions & Answers 0 10-26-2007 03:59 AM
how to write perl substitute command in shell scripts param_it UNIX for Dummies Questions & Answers 3 07-03-2007 01:09 AM
Substitute File name vanand420 Shell Programming and Scripting 22 03-13-2007 11:40 PM
Substitute in vi kingdbag UNIX for Dummies Questions & Answers 5 01-17-2007 11:42 AM
sed substitute situation newbreed1 UNIX for Dummies Questions & Answers 16 06-03-2005 11:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-10-2005
Registered User
 

Join Date: Nov 2001
Posts: 59
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.
Reply With Quote
Forum Sponsor
  #2  
Old 03-10-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,589
command mode:

:1,$s/WORD_TO_REPLACE/WORD_TO_SUBSTITUTE/g
Reply With Quote
  #3  
Old 03-10-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
or

:%s/John/Mark/g
Reply With Quote
  #4  
Old 03-26-2005
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Or

:g /John/s//Mark/g


OR From outside the file...

# cat file.in | sed 's/John/Mark/g' > file.out
__________________
My brain is your brain
Reply With Quote
  #5  
Old 03-26-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
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
Reply With Quote
  #6  
Old 03-26-2005
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
yea, I was just showing all known uses....

grep <pattern> file.in | sed 's/John/Mark/g' > file.out
__________________
My brain is your brain
Reply With Quote
  #7  
Old 03-26-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
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 ??
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0