The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-26-2007
param_it param_it is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 17
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
  #2 (permalink)  
Old 06-26-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
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 ?
  #3 (permalink)  
Old 06-26-2007
param_it param_it is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 17
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.
  #4 (permalink)  
Old 06-26-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

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

Join Date: Jun 2007
Posts: 17
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.
  #6 (permalink)  
Old 06-26-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0