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
Want to replace characters arndorff Shell Programming and Scripting 5 01-29-2008 12:05 PM
How to replace characters 7 through 14 of every line in a file jakSun8 Shell Programming and Scripting 9 12-12-2007 10:13 PM
Replace Special characters in a file solai UNIX for Dummies Questions & Answers 1 07-13-2006 07:36 AM
Replace characters in a string using their ascii value roops Shell Programming and Scripting 2 03-03-2005 09:51 PM
how to replace control characters using sed? hillxy Shell Programming and Scripting 5 10-16-2003 07:12 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-26-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
Replace Characters...

In a file, How do I replace a set number of characters in each line?

For example.... substitute the first 54 characters of each line with mv?

Thanks!
Lisa
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-26-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,991
'sed' is your friend - sed1liners
Code:
sed 's/^.\{54\}/mv/' myFile.txt

Last edited by vgersh99; 10-26-2006 at 01:23 PM.
Reply With Quote
  #3 (permalink)  
Old 10-26-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed "s/^.\{54\}/mv/" x
Reply With Quote
  #4 (permalink)  
Old 10-26-2006
Registered User
 

Join Date: Oct 2006
Posts: 2
Thank you so much.... it was exactly what I needed!!

Can I just ask.... is the "." considered a wildcard in this code?
Reply With Quote
  #5 (permalink)  
Old 10-26-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Yes "." matches any character
Reply With Quote
  #6 (permalink)  
Old 10-26-2006
Registered User
 

Join Date: Jul 2006
Posts: 32
Quote:
Originally Posted by vgersh99
'sed' is your friend - sed1liners
Code:
sed 's/^.\{54\}/mv/' myFile.txt
vgersh99

I have a doubt in this. If i am inside the file that is
vi myFile.txt.
Then how can I use the command, should I use the sed word?
Reply With Quote
  #7 (permalink)  
Old 10-26-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,991
no, but use the same 'substitute' expression in the vi 'command' mode.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:47 PM.


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

Content Relevant URLs by vBSEO 3.2.0