Re: add string into the file (somewhere in the middle)



On Mon, 21 Apr 2008 19:11:23 +0000 (UTC), Jahoo <jahoo@xxxxx> wrote in
<fuiosq$vk8$6@xxxxxxxxxxxx>:

I'm wondering howto make such thing:
i would like to add specific string into some configuration files.

but not in the end of file (it's obviously easy) but somewhere in the
middle
for example
in my.cnf after line [mysqld] I'd like to add:
key_buffer = 16M

or in /etc/xinetd.d/echo after lines:
service echo
{
disable = yes

I'd like to add:
wait = yes

What you're looking for is an algorithm. It would be something like
this:

open file
get first line
while you have a line
check the line to see if its the one after
which you want to insert lines
if so, insert the lines
get next line
end while
close file

You should start reading the reference on file functions
<http://www.php.net/manual/en/refs.fileprocess.file.php>.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
.



Relevant Pages