Moving part of a textfile - where to start?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Moving part of a textfile - where to start?

Post by Linkjames »

I have a large text file (Several hundred lines) and I need to take line 21 through line 28 and copy them to line 41, shunting all the text below down to make space.

It looks like it should be obvious, but I can't for the life of me figure out how to do it. Could someone please point my dumb arse in the right direction please?

Ta - LinkJames
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Don't try and do it within the text file.
Take line 1 - 20 and put it into $first or something.
Then line 21-28 into $second
Line 29-40 into $third
Line 41 + to $forth.

Code: Select all

$file = $first.$second.$third.$second.$forth;
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I had something more complex in mind, but that works great too. ;)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

or learn how to use sed, the streaming editor :)
Post Reply