Replacing text which contains html tags - character escaping problem
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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
We are generating hourly html reports from logs.
Team members have to open, change a few things on these html reports by hand on windows.
But I told them they don't have to do these by hand every hour and as soon as I told them I can search and replace text recursively with perl pie command on linux With the help of cron
They loved it.
So I write a basic bash script.
It generates the html report, searches three long text fragments and replaces it with given text.
But one of the text block that I have to remove is this:
I have built systems of monitor and analysis pages, often with simple mysql back ends updated by scripts, and NEVER wanted to edit pages in place. I always GENERATED the pages using perl or bash. Today I would be likely to use python, but even old ksh without extensions or updates could do this job.
It requires more thought, and more script, but correct edits when multiple embedded delimiters are involved is tricky for any tool. Generating the correct page is FAR easier.
Here is another idea to add to the above: if you MUST edit, try using the original page as a base for a template. Replace the part that will change into something easy to search for and that contains few or no delimiters. Generate your finished pages from the templates by replacing ONLY those easy to find and replace field holders in a copy of the template.
There are so many different kinds of software tools for search and replace simply because it is a tricky problem under some conditions. GENERATING text (and html xhtml is just formatted test) is far easier, and has been solved by every "hello world" program ever written in pretty much the same way.
I also have an idea for a combined approach, but it would require identifying comments added to the html document to delimit the blocks to be replaced. Easier to generate the page directly, but an interesting problem to consider.
imho, even if you must edit (rather than going with my prev suggestion), nonetheless one-liners are fiddly and hard to debug even if it can be done.
Just write a proper Perl program to do the editing, gives you much more control and much easier to debug.
Perl is really good at this sort of thing (or pick another lang if you prefer).