The UNIX and Linux Forums  

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
select a portion of a file into a CSV anju Shell Programming and Scripting 8 02-27-2008 10:50 PM
extract date portion from file misenkiser Shell Programming and Scripting 5 10-06-2006 02:37 AM
extract a portion of log file chandra004 Shell Programming and Scripting 8 08-03-2006 05:20 PM
display a portion of lines from file champion UNIX for Dummies Questions & Answers 6 09-20-2005 08:11 AM
remove portion of file methos Shell Programming and Scripting 13 08-16-2002 06:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 3
Delete Portion of a file

hi i would like to know whether i can delete a part of a file in C
for eg. if my file contained
1234567890
and i want to delete
456
so that it becomes
1237890

is there a way i can do this.

well, one way i can achieve this is by creating a new file, copy whatever i want, then delete the old file and rename the new file with the name of the old file.
but i was wondering whether it can be done in directly, i.e. without doing any copies.

plz help
regards
Edit/Delete Message
Reply With Quote
Forum Sponsor
  #2  
Old 01-19-2007
elzalem's Avatar
Registered User
 

Join Date: Nov 2006
Location: Lebanon
Posts: 33
good question

The only method i know is the one u just wrote, but what if u can overwrite the unwanted characters by shifting the ones after them to the left, then insert the END OF FILE (EOF) in it's correct position? i don't know if it's possible, and there's the matter of space: will the file be shrinked or it'll remain the same size? because we're not "deleting" anything, we'r just changing the sequence of characters....
Reply With Quote
  #3  
Old 01-19-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
It is possible to move characters down with a read and write loop and you can call truncate() to shorten the file.
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 10:38 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