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
replace character in a string pattern and save the change in same file mihir0011 Shell Programming and Scripting 2 09-26-2007 02:31 PM
replace a string with content from another file afatguy Shell Programming and Scripting 4 09-14-2006 06:25 PM
replace a string in a file ratan2204 Shell Programming and Scripting 7 05-10-2006 06:40 AM
Replace all occurances of a string in all file-/foldernames, recursively TheMJ Shell Programming and Scripting 2 04-11-2006 10:40 PM
replace string in binary file sg1207 Shell Programming and Scripting 2 07-28-2004 08:26 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2007
Registered User
 

Join Date: Jun 2007
Posts: 10
Thumbs up How to replace the string in unix file?

Hi

Am getting "Line too long" error in opening a file using vi editor but it is opening using cat.

How can i edit the file to replace some string in it.


Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-26-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
use sed / perl - that should be quite easier if you are not able to edit the file in place


could you post some examples on what need to be done ?
Reply With Quote
  #3 (permalink)  
Old 06-26-2007
Registered User
 

Join Date: Jun 2007
Posts: 10
Thanks for your reply.

When am using sed, the command is not replacing the string.
sed -e 's/notes2/notes/g' expoutnotesall > outfile
I used ed in HOME argument format also in scrip as

ed $1 <<-EOT
1,\$s/notes2/notes/g
w
q
EOT


Can u tell me exactly how to use sed /perl here in shell scripts.
Reply With Quote
  #4 (permalink)  
Old 06-26-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Param,
As Matrixmadhan said, could you post a sample of your input
and expected output?
Reply With Quote
  #5 (permalink)  
Old 06-26-2007
Registered User
 

Join Date: Jun 2007
Posts: 10
sorry, i cant give the contnent of input file.
This file contains the string "notes2" which has to be replaced by the string "notes".

Since i was not able to open in vi editor, i cant give the input file.
It is an export file produced by some command in our application which is in data file format. Using cat command i was able to view the file content.
Reply With Quote
  #6 (permalink)  
Old 06-26-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by param_it View Post
sorry, i cant give the contnent of input file.
This file contains the string "notes2" which has to be replaced by the string "notes".

Since i was not able to open in vi editor, i cant give the input file.
It is an export file produced by some command in our application which is in data file format. Using cat command i was able to view the file content.
Use fold command to cut the text in your file into multiple lines with 80 characters per line
Code:
fold -80 filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:08 PM.


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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0