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
Delete first line from file and more.... dfb500 Shell Programming and Scripting 6 07-02-2009 10:04 AM
How to delete line from a file ramezernest UNIX for Dummies Questions & Answers 0 11-01-2007 11:56 AM
delete line in file with sed forever_49ers Shell Programming and Scripting 8 09-12-2007 08:39 AM
delete line in a file dta4316 Shell Programming and Scripting 12 05-18-2005 10:20 AM
Delete line(s) from file elchalateco UNIX for Dummies Questions & Answers 4 10-11-2002 01:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-28-2007
rohini rohini is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 3
Delete a line from a file

Hi,

Need to delete a line from a file, file is too large so cannot use vi.

I know the line number that has to be deleted...

How can this be done ?
  #2 (permalink)  
Old 02-28-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by rohini
Hi,

Need to delete a line from a file, file is too large so cannot use vi.

I know the line number that has to be deleted...

How can this be done ?
sed <linenum>d file > file2
  #3 (permalink)  
Old 02-28-2007
Manish Jha Manish Jha is offline
Registered User
  
 

Join Date: Dec 2005
Location: Boston, USA
Posts: 65
sed 'linenumberd' filename > newfilename

e.g. to delete 5th line
sed '5d' filename > newfilename
  #4 (permalink)  
Old 01-06-2009
shabs1985 shabs1985 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 13
hi how do i delete a block of text from a text file within known line numbers. e.g. from line 43 to lint 58. between and including these kines, i want the block deleted.
  #5 (permalink)  
Old 01-07-2009
sivakumar.rj sivakumar.rj is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 74
the sed command can be used to delete the specific lines in a file

sed '43,58d' infile > outfile

  #6 (permalink)  
Old 01-07-2009
palanisvr palanisvr is offline
Registered User
  
 

Join Date: Mar 2007
Location: India
Posts: 16
Line Deletion

Try this :

##--NOn interactive deletion of lines using vi- editor
vi - a.txt <<END
:11d
:12d
:x
END

##the above code will delete 11th and 42nd line , saves the file and exits

dump the above code in a script and execute it ...

you can also achive the same using sed but sed is a temporary one it wont make the changes permanent to the source file....
  #7 (permalink)  
Old 01-07-2009
shabs1985 shabs1985 is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 13
Question

Quote:
Originally Posted by palanisvr View Post
Try this :

##--NOn interactive deletion of lines using vi- editor
vi - a.txt <<END
:11d
:12d
:x
END

##the above code will delete 11th and 42nd line , saves the file and exits

dump the above code in a script and execute it ...

you can also achive the same using sed but sed is a temporary one it wont make the changes permanent to the source file....
thats fine. how do i do it in sed, i could pipe the changes into a new file. i prefer single line commands as i haven't mastered executing scripts yet.
Sponsored Links
Closed Thread

Bookmarks

Tags
sed syntax

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 10:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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