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
How to replace specific text line out of multiple occurance madhusmita Shell Programming and Scripting 5 06-17-2008 01:03 PM
How to search and replace text in same file Vrgurav Shell Programming and Scripting 1 04-25-2008 06:20 AM
read space filled file and replace text at specific position COD Shell Programming and Scripting 6 04-21-2008 05:40 AM
automating file search and replace text ommatidia Shell Programming and Scripting 3 02-28-2008 04:40 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM

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

Join Date: Jun 2008
Posts: 17
overwriting a line in text file

I have a text file with following content (3 lines)

filename : output.txt

first line:12/12/2008
second line:12/12/2008
third line:Y


I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before.

I tried using cat output.txt |sed -e 's/third line:Y/third line:Y/' , but in this case it writes the output to some other file and we have to replace that old file with new file.

Do we have a way to do this without replacing the old file with new file after using sed command or can we do this any command other than sed?

Last edited by santosham; 06-24-2008 at 11:16 AM..
  #2 (permalink)  
Old 06-24-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
Code:
sed -i 's/third line:Y/third line:N/' your-file
  #3 (permalink)  
Old 06-24-2008
santosham santosham is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 17
its says .. 'i' is an illegal option

thanks
  #4 (permalink)  
Old 06-25-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
your sed does not support the inline edit -i option.

using Perl:
Code:
perl -pi -e 's/third line:Y/third line:N/' output.txt
  #5 (permalink)  
Old 06-25-2008
eBay's Avatar
eBay eBay is offline
Registered User
  
 

Join Date: Jun 2008
Location: Spokane
Posts: 12
Regarding only changing the third line:

$ cat f
yy
yy
yy
yy
yy
$ sed '3s/yy/nn/' f
yy
yy
nn
yy
yy

Does this help?

Last edited by eBay; 06-25-2008 at 06:35 PM..
Sponsored Links
Closed Thread

Bookmarks

Tags
perl, sed

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 01:02 AM.


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