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 > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove first N bytes and last N bytes from a binary file on AIX. naveendronavall Shell Programming and Scripting 1 05-24-2008 11:06 AM
How to delete initial N bytes from the starting of the file using sed? jockey007 Shell Programming and Scripting 3 11-19-2007 08:26 PM
Delete lines starting with XX or YY or ZZ or .... orno Shell Programming and Scripting 2 11-13-2007 05:33 PM
delete bytes from file Loriel Shell Programming and Scripting 6 04-13-2006 01:27 PM
Take a file from the system and put on tape and reset the file to 0 bytes JackieRyan26 UNIX for Dummies Questions & Answers 1 09-06-2001 05:08 PM

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 11-15-2007
jockey007 jockey007 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 18
How to delete N bytes from the starting of the file from a C function???

Hi,
I want to delete the initial few lines (or even bytes) from a file.
I want to do this from a C function & this is in Linux platform.
The truncate & ftruncate is allowing me to delete bytes from the end only.
Any linux C function calls or ideas or any suggestions??

I'm in a dead lock..Plz help

Wishes
Jay
  #2 (permalink)  
Old 11-15-2007
jockey007 jockey007 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 18
I even tried

lseek(fd, (off_t)numOfBytes, SEEK_SET);
i=ftruncate(fd,1000);

but this didn't help
  #3 (permalink)  
Old 11-15-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
No, there is no function to delete from the middle of a file, only to truncate.

You have two options

(a) open one file, read buffer fulls and write earlier in the file until you get to the end then truncate

(b) open a new file, copy the data you want to keep to the new file and then close it and rename it onto the original.
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 02:48 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