The command would be something like this:

find /wwwdir -name \*.txt -print | xargs sed -i s/oldtext/newtext/gi


Sent via BlackBerry by AT&T

-----Original Message-----
From: Steve <>
Date: Sat, 12 Jun 2010 15:24:39 
To: <>
Subject: Re: [PHP] How to change the first line of a text file
On 6/12/2010 2:10 PM, 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;

Something like this should do what you want:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to