Delete from one row and up in a txt file?

Questions about programming languages and debugging
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Delete from one row and up in a txt file?

Post by ayu »

Could anyone help me to like, make or get a code/proggy that deletes everything from one row in a text document and up?

because i have dictionarys with 1500000000 words, and sometimes i want to delete everything from like row 80000 and up..and that takes time xP
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Here's a PHP script:

Code: Select all

<?PHP

$file = file('dictionary.txt');

$open = fopen('newdictionary.txt', 'a');

for($a = 8000; $a < count($file); $a++)
{
fwrite($open, $file[$a]);
}

fclose($open);

?>
Last edited by Gogeta70 on 27 Jul 2006, 08:42, edited 1 time in total.
¯\_(ツ)_/¯ It works on my machine...

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Don't you have something more C or VBisch? =P
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Nope... "Beggars can't be choosers."
¯\_(ツ)_/¯ It works on my machine...

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

He just gave you the receipt to do it. Just read :wink:

[ This will work on any language, pick-up the one you like]

Open your wordlist ( File s )
Create a new .txt file ( File x)
For ( int i = 8000; ! s.endOfFile ; i++)
x = s(i);

Close all file.

This should work imo

Ps: I think gogeta used this strategy.
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

Yeah, that's what i did. Read from line 8,000 to the end.
¯\_(ツ)_/¯ It works on my machine...

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Ok, but i don't want it to read to the end :/ i want it to read and delete from row 8000 and to the start
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

... If you don't understand the programming language, you shouldn't comment on it. Neo, when i said it 'read' from line 8000 i was saying that i rewrote the dictionary file, making line 8000 line 1.
¯\_(ツ)_/¯ It works on my machine...

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Comment? :/ no no, it was just that i didn't understand it fully, and you didn't explain it so that i understod.
"The best place to hide a tree, is in a forest"

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

I think gogeta tough that you knew the basic into programming :wink:
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
18
Location: Belgistahn
Contact:

Post by FrankB »

nerdzoncrack wrote:Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
:)
"Give a man a fish, he'll leave you in rest for one day,
give a man internet access, he'll never bother you again".

--
FrankB

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Anyway tried the php code, and it doesn't work, it seems like it adds everything from row 0 to 8000 instead of deleting it. because the file was like 1 mb bigger now :?
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

make sure to open newdictionary.txt.
¯\_(ツ)_/¯ It works on my machine...

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

yeah but, when i open the php page, it creates the newdictionary.txt ...but that files is 1-2 mb bigger then the old file :S i suposed i am doing it wrong? =P
"The best place to hide a tree, is in a forest"

User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Post by Gogeta70 »

If you open the php file multiple times, it'll append the data to the file, not overwrite it.
¯\_(ツ)_/¯ It works on my machine...

Post Reply