Raised This Month: $ Target: $400
 0% 

Remove a line from a file?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 05-02-2011 , 18:47   Remove a line from a file?
Reply With Quote #1

I want to remove a line from a file which contains a specific string. I did it by doing an empty write_file on that line but that leaves a blank row in a file. How can I delete the line without leaving a blank row?
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-02-2011 , 19:14   Re: Remove a line from a file?
Reply With Quote #2

Read the whole file contents, then write all of the contents into a new file without that 1 line.
Then delete the old file and rename the new file to the old one.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 05-04-2011 , 17:01   Re: Remove a line from a file?
Reply With Quote #3

Is there another option?

Because the file can have over 2000 lines (steam ids) and it deletes a line 5-6 times per map. The file is accessed over 300 times per map.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-04-2011 , 17:10   Re: Remove a line from a file?
Reply With Quote #4

Desikac
Bufferize the file in an array on plugin_cfg and work with array directly, save it to file on plugin_end. But this will use up as much memory as file size is. You can also try using ftell/fseek (check file.inc).
__________________


Last edited by SonicSonedit; 05-04-2011 at 17:16.
SonicSonedit is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-04-2011 , 17:13   Re: Remove a line from a file?
Reply With Quote #5

Use write_file and specify the line number, the wanted line won't really be removed but it will be blank.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-04-2011 , 17:17   Re: Remove a line from a file?
Reply With Quote #6

ConnorMcLeod
I know it's offtopic, but can you tell me, array in pawn use only cellsize*arraysize bytes for memory allocation, or (cellsize+2)*arraysize or (cellsize+4)*arraysize ?
__________________


Last edited by SonicSonedit; 05-04-2011 at 17:22.
SonicSonedit is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-04-2011 , 17:45   Re: Remove a line from a file?
Reply With Quote #7

I have no idea of what you are talking about ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-04-2011 , 19:22   Re: Remove a line from a file?
Reply With Quote #8

ConnorMcLeod
I mean, is pawn using just a dinamic array, one-way vector (with data* next) or two-way vector (with data* next, prev) ?

By saying "one-way vector" I mean something like this (sorry for my poor knowledge or english computer terms):
PHP Code:
struct TVectorData
{
    
TVectorDatanext;
    
voiddata;
};

class 
TVector
{
    
int Size;
    
struct TVectorDataVectorData;
}; 
(rough example, but you get the idea).
__________________


Last edited by SonicSonedit; 05-04-2011 at 19:32.
SonicSonedit is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2011 , 19:23   Re: Remove a line from a file?
Reply With Quote #9

Quote:
Originally Posted by SonicSonedit View Post
ConnorMcLeod
I mean, is pawn using an array, one-way (with data* next) vector or two-way (with data* next, prev) vector?
Have you consulted the PAWN manual?
__________________
fysiks is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-04-2011 , 19:43   Re: Remove a line from a file?
Reply With Quote #10

Quote:
_first (arrayid, index, &success = 0);
_next (arrayid, index, &success = 0);
_prev (arrayid, index, &success = 0);
_last (arrayid, index, &success = 0);
Ok, got it.
__________________


Last edited by SonicSonedit; 05-04-2011 at 19:50.
SonicSonedit is offline
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT -4. The time now is 04:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode