Re: How to change the first line of a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2010-06-12 at 14:10 -0700, Richard Kurth wrote:

> I have around 6000 text files and I need to change the first line on every 
> one of them.
> 
> The first line is the title of the article and I need it look like this 
> <title>the name of the article</title>
> 
> every file has the first line and the it starts the article on the second 
> line
> 
> The files are in many directory under one main directory
> like this
> 
> top directory
>             fashion-school
>             Dogs
>             DentalAssistant
>             etc..........
> 
> I need a script that will loop through each directory look at each file 
> extract the first line and replace it with the example above.
> I have figured out how to pull the first line into an array but I don't no 
> where to go from there to look in each directory and the write the data back 
> at the top.
> 
> $f = file('GENERAL HISTORY OF DOGS.txt');
> $a = '<title>' . $f[0] . '</title>';
> echo $a;
>  
> 
> 


Rather than use PHP for this I would look at using the find and sed
tools to edit the files.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux