LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 01:57 PM   #1
dougp23
Member
 
Registered: Oct 2006
Posts: 43

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, 02:30 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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 03:01 PM.
 
Old 10-30-2006, 02:30 PM   #3
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
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, 03:01 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

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


Reply



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 11:42 AM
writing text to the beginning of a file linuxmandrake Linux - Newbie 3 03-26-2006 10:55 PM
Add text to many files Kanon Linux - General 4 08-28-2005 03:27 AM
How to add data at file beginning in C? Nad0xFF Programming 8 04-17-2005 11:48 AM
Real Beginning... How do I burn Fedora files onto CD? Sociologo Fedora 3 11-23-2003 01:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:36 AM.

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
Open Source Consulting | Domain Registration