ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I have about 1000 html files in a directory & need to append 4 lines of PHP code to the top of each of these files, it's for a PHPnuke site in case your wondering.
I also have to append 3 lines of PHP code to the end of the html files but I know I can do that with
'cat my-php-code >> *.html' or am I wrong on that??
The trouble is I have no idea how to append something to the beginning of a file.
A bash or perl script that does the job would be very much appreciated, or even a point in the right direction, as you can imagine it wouldnt be very nice to have to open all 997 files with VI & paste the code in.
the first argument to this script is a file containing the lines
that need to be inserted at the top, and the second is
the file into which the lines need to be inserted
I'm not sure about "appending" to the beginning of a file, but you could reverse the process like so:
1. Append the three lines of code to the end of each .html file.
2. Append the each .html file to a separate file containing just the four PHP lines you need.
I'm thinking a for loop would do ok if you want to automate it.
I still cant do it but both of your replys have put me on the right track.
Thanks for the reply's.
Any ideas how I use all files in a directory ending in .html as a variable?
Sorry if I'm asking some basic questions here but I'm way in over my head here, I try to declare $1 as a variable containing all .html files in my current directory like so:
$1=*.html
& as you can see it dosent work.
How do I declare all the .html files as a variable so I can manipulate all the files at once?
For future reference everyone, this also works, test is the name of the file containing the text you want to add to the top of all html files in the current directory, it work's!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.