LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Add Text to Beginning of 200 Files (https://www.linuxquestions.org/questions/linux-newbie-8/add-text-to-beginning-of-200-files-496993/)

dougp23 10-30-2006 01:57 PM

Add Text to Beginning of 200 Files
 
I have 200 php files. I want to add 2 lines of text to the beginning of each one. (I plan to open source the app, so 2 lines about the GPL and what it all means.)

Is there anyway to do that? I looked at cat, but it can append or overwrite. I want to run a little script that will add the same 2 lines I specify to all 200 *.php files.

Thanks.

acid_kewpie 10-30-2006 02:30 PM

there are a million ways to do this, off hand i would say create a header file containing what you want, and then just cat that file and a php file and redirect it.

Code:

for file in original/*.php
do
  cat header $file > new/$(basename $file)
done


phil.d.g 10-30-2006 02:30 PM

Sounds like the perfect job for sed. There are plenty of quickstart guides about the internet that will do a better job of explaining how to use it than I can in a post.

acid_kewpie 10-30-2006 03:01 PM

initially i was gonna suggest sed, but you're still really going to have two seperate files to join together somehow.


All times are GMT -5. The time now is 06:25 PM.