FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Read file backwards





umeshtangnu
Hey,

I'm writing a script that appends to a file. Would it be possible if someone could tell me how to read a file from down up rather form up down. Example:

the
dog
sat

I want this to happen
sat
dog
the

So the file is read from down up line by line.

Many thanks in advance,
GSIS
How many lines?

How long is each line?

What language will the script be in?

My first thoughts -

1 - Read everything into an array. Read each line from the array starting at last element and working down to the first.

2 - Put it all in a mySQL table with the line number. Read it using ORDER BY LineNumber DESCENDING (or whatever the syntax is).

3 - Wait until someone who knows your scripting language comes along. There's probably a very easy way!
MrBlueSky
As GSIS said: please give some more information.

But here is a solution in Perl:

Code:

use strict;

open (F, "<$ARGV[0]");

my @lines = <F>;

print reverse @lines;
Related topics
How to get backup from server to my computer
The more you know...
Name a (wacky?) English language cultural difference.
Hex editing in PHP
Test your eyes !!!
how to compress a file using php ?
need help
PHP Read File Help needed.
Hey.
Sending arbitrary data to/from PHP
Deleting certain lines from text file
Can You Read This?
About Adding Text to Beginning of File
Hello from aidniaidni
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.