Nice tips, Hunter.

In the case of spaces in the filename, I think you'd need double-quotes around $i though, as in:
/bin/ls *.php | while read i ; do echo "text" >> "$i" ; done

Also, the find command can do all that w/out the while loop at all. I think it'd be something like this: /bin/find ./ -name "*.php" -exec echo "processing {}" \; -exec echo "text" >> {} \;

--
-Eric 'shubes'


On 10/21/2010 10:27 AM, Hunter Kreie wrote:
Although the for loop will probably work for your PHP files, I generally prefer 
using a different method for processing lists of files.

/bin/ls *.php | while read i ; do echo "text">>  $i ; done

This will handle files with spaces in them and gives you more flexibility with 
the input list. For instance, if you have a bunch of subdirectories, you could 
use find instead.

/bin/find ./ -name "*.php" | while read i ; do echo "processing $i" ; echo 
"text">>  $i ; done

When piping the command to a while loop like this, I use the full path to the 
command (/bin/ls instead of ls) in order to prevent shell aliases from having 
any effect.

Hunter


From: [email protected] 
[mailto:[email protected]] On Behalf Of mike hoy
Sent: Wednesday, October 20, 2010 11:48 PM
To: Main PLUG discussion list
Subject: Re: using echo 'text'>  file (to add to last line of several documents)

thanks for the help!
On Wed, Oct 20, 2010 at 11:34 PM, der.hans<[email protected]>  wrote:
Am 20. Oct, 2010 schwätzte mike hoy so:
one last thing:

echo 'text'>>  1.php 2.php 3.php

or

echo 'text'>>  *.php

for i in *.php; do echo 'text'>>$i; done

You could also do a sed inline script to grab them all, but for i in is
simple enough syntax for me.

would be nice, but don't work any input on that? or am I to write a bash
script?

Well, the "echo 'text'>>1.php" is already a bash script :)

ciao,

der.hans



On Wed, Oct 20, 2010 at 11:24 PM, mike hoy<[email protected]>  wrote:
ah nice, thanks

On Wed, Oct 20, 2010 at 11:25 PM, der.hans<[email protected]>  wrote:
Am 20. Oct, 2010 schwätzte mike hoy so:


  is it possible to simply add text to the bottom of multiple files or even
one?

Append (>>) rather than truncate (>).


  for example let's say I want to add to the bottom of several files:

<?php include("../includes/footer.php"); ?>  to the bottom of 1.php

echo '<?php include("../includes/footer.php"); ?>'>  1.php

echo '<?php include("../includes/footer.php"); ?>'>>  1.php

ciao,

der.hans
--
#  http://www.LuftHans.com/        http://www.LuftHans.com/Classes/
#  Passwords are like underwear. You don't share them, you don't hang them
on
#  your monitor, or under your keyboard, you don't email them, or put them
on
#  a web site, and you must change them very often. -- Unknown
---------------------------------------------------
PLUG-discuss mailing list - [email protected]
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss



--
Mike Hoy







---------------------------------------------------
PLUG-discuss mailing list - [email protected]
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

Reply via email to