LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-30-2006, 02:57 PM   #1
dougp23
Member
 
Registered: Oct 2006
Posts: 37

Rep: Reputation: 15
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.
 
Old 10-30-2006, 03:30 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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

Last edited by acid_kewpie; 10-30-2006 at 04:01 PM.
 
Old 10-30-2006, 03:30 PM   #3
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
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.
 
Old 10-30-2006, 04:01 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 12:42 PM
writing text to the beginning of a file linuxmandrake Linux - Newbie 3 03-26-2006 11:55 PM
Add text to many files Kanon Linux - General 4 08-28-2005 04:27 AM
How to add data at file beginning in C? Nad0xFF Programming 8 04-17-2005 12:48 PM
Real Beginning... How do I burn Fedora files onto CD? Sociologo Fedora 3 11-23-2003 02:33 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration