Prev: Why is there HTML in the error_log output? Please make it stop.
Next: howto run sql script with php?
From: "Richard Kurth" on 12 Jun 2010 17:10 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;
From: Ashley Sheridan on 12 Jun 2010 17:43 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
From: Steve on 12 Jun 2010 18:24 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: http://pastebin.com/jKvAiGYa
From: mcgiddin on 12 Jun 2010 18:29 If you're running on a *nix system you may want to look at using find, xargs, and sed. Sorry I can't give you the syntax at the moment but you can google for the three of them and find several good examples. Matt Sent via BlackBerry by AT&T -----Original Message----- From: Steve <admin(a)ultramegatech.com> Date: Sat, 12 Jun 2010 15:24:39 To: <php-general(a)lists.php.net> 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: http://pastebin.com/jKvAiGYa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
From: mcgiddin on 12 Jun 2010 18:31
The command would be something like this: find /wwwdir -name \*.txt -print | xargs sed -i s/oldtext/newtext/gi Matt Sent via BlackBerry by AT&T -----Original Message----- From: Steve <admin(a)ultramegatech.com> Date: Sat, 12 Jun 2010 15:24:39 To: <php-general(a)lists.php.net> 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: http://pastebin.com/jKvAiGYa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |