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 Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting lines in text file hern14 UNIX for Dummies Questions & Answers 5 05-16-2008 03:03 PM
Deleting lines in a file reachsamir Shell Programming and Scripting 2 05-29-2007 11:17 AM
Deleting last 2 lines from the file. videsh77 Shell Programming and Scripting 4 04-06-2007 01:14 PM
Deleting Lines from .csv file 009satya Shell Programming and Scripting 3 11-14-2006 03:41 AM
deleting lines in a log file BG_JrAdmin Shell Programming and Scripting 2 08-22-2006 11:12 AM

Reply
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 09-21-2005
Nirgude07 Nirgude07 is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 5
Question Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file.
  #2 (permalink)  
Old 09-21-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
I could think of this:
Code:
sed -n "${to},${from}p" file_to_cut_lines_from | cat > file_to_cut_lines_from
You can use this to get a block of lines from a file, deleting the rest of the lines (because of the >).

This works in ksh, but is not portable in sh and bash. This has to do with the way ksh treats the '>'. There is a post where Perderabo has given an explaination for this - but I cant seem to remember where that post is...

Last edited by blowtorch; 09-21-2005 at 12:58 PM..
  #3 (permalink)  
Old 09-21-2005
Nirgude07 Nirgude07 is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 5
Actually I have 8GB file which contains 200,000 records and I want to delete first 50,000 records without opening the file. At the same time I don't want to create another file once I delete the records because of space problem on server.

Is there any way I can delete 50,000 lines from 'abc.dat' and redirect output in the 'abc.dat' only.
  #4 (permalink)  
Old 09-21-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
ed can do this but it does create a temp file.
  #5 (permalink)  
Old 09-21-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Records are potentially very different from lines. You could have your own delimiters and have a record spanning several lines. If each line is a single record, then you could still run the following command under ksh:
Code:
sed -n "50000,200000p" file_to_cut_lines_from | cat > file_to_cut_lines_from
Though I really dont know if you can do this with such a large file. Even if it works, it will take a really long time to get through the file.
  #6 (permalink)  
Old 09-21-2005
Nirgude07 Nirgude07 is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 5
It's not working....it's deleting the whole file..
  #7 (permalink)  
Old 09-21-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Are you running this under ksh? It will *only* work under ksh and *not* under bash and sh.
Sponsored Links
Reply

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 12:24 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