Linux - NewbieThis 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
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.
For your information, there are html files witch are updating automatically every min.
So far okay, but I want to change the background color from #FFFFFF to #000000 and a picture.
All the html files are located in many directories :
If so, then just change the one line in the one stylesheet and all the XHTML documents pointing to it will have their backgrounds changed.
About adding the image, you can insert a line easily using sed. But first you must identify a pattern in the file which you can use for a reference. Which unique HTML element do you want the image inserted before or after?
Please show the exact string you want to replace to make the color change.
It would be more practical to make the changes upstream in the script that is generating the XHTML files in the first place. Even then the CSS advice still stands.
But if you are going to watch the directory with inotify / incron and run a script, that script could run sed to insert lines or even replace lines. However, for that to work you have to be able to identify the exact place in the XHTML file for sed to be able do its thing. For example, if I want "foobar" added after the 15th line in index.html, making a backup copy of the original:
Code:
sed -i.bak -e '15afoobar' index.html
If I want "foobar" added before an element, say P of the "note" class, it is also rather easy:
Code:
sed -i.bak -e '/<p class="note">/ifoobar' index.html
If I want to add "foobar" after that same element, it is more tricky:
Code:
sed -i.bak -n '1h;1!H;${g;s/<p class="note".*<\/p>/&\nfoobar/;p;}' index.html
When it gets that tricky you are better off using perl. Again, it is easier if you make the changes upstream in the source of the script that is making your XHTML files.
Last edited by Turbocapitalist; 08-31-2017 at 03:49 AM.
Ok. If that is a binary then there is not much chance of being able to modify it. The next best thing is to have whatever is calling that binary to also call your script.
As for your script, if that string is unique and it does not vary at all, not even in the number of spaces, then you can use sed still:
Code:
sed -i.orig -E -e 's|(background-color:) #ffffff;|\1 #000;\ncolor: #fff;|' index.html
If there is variation in that string or if it is not unique in each file then you must create a different pattern. See "man sed" and "man 7 regex" for reference.
Hi Erik,
you say changing the color/picture is no problem. So your only Problem is, that it changes back every minute, right?
Do you know how the command that does these unwanted changes is executed? If it is via cron, the easiest way would be to edit the cron entry and add your code to change color & image.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.