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
Removing the first and last lines in a file naveendronavall Shell Programming and Scripting 2 12-29-2007 10:22 PM
Removing the first and last lines in a file naveendronavall AIX 1 12-29-2007 08:44 PM
Removing lines within a file tookers Shell Programming and Scripting 3 08-22-2006 06:49 AM
Removing lines from a file PradeepRed Shell Programming and Scripting 4 12-17-2005 03:34 AM
Removing lines in a text file. WABonnett Shell Programming and Scripting 4 11-25-2003 08:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-14-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
Removing lines from a file

I'm trying to find a command which will allow me to remove a range of lines (2-4) from a .dat file from the command line without opening the file.

Someone mentioned using the ex command?

Does anyone have any ideas?

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-14-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
sed '2,4d' oldfile > newfile
mv newfile oldfile
Reply With Quote
  #3  
Old 11-14-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
Thank you!
Reply With Quote
  #4  
Old 11-14-2006
Registered User
 

Join Date: Nov 2006
Posts: 5
Is there a way of substituting one word for another word, in the same manner?
Reply With Quote
  #5  
Old 11-14-2006
Registered User
 

Join Date: Jul 2006
Posts: 32
After u open the File in vi editor

:s/oldword/newword/g

Does replacing old word with new one everywhere in the file.
Reply With Quote
  #6  
Old 11-14-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Quote:
Originally Posted by venu_nbk
After u open the File in vi editor

:s/oldword/newword/g

Does replacing old word with new one everywhere in the file.
no, this replaces ALL the occurances of 'oldword' to 'newword' on the CURRENT line where your cursor is.

Last edited by vgersh99; 11-14-2006 at 03:52 PM.
Reply With Quote
  #7  
Old 11-14-2006
Registered User
 

Join Date: Jul 2006
Posts: 32
Quote:
Originally Posted by vgersh99
no, this replace ALL the occurances of 'oldword' to 'newword' on the CURRENT line where your cursor is.
Sorry, its this one
:%s/oldword/newword/g
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:05 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