Big problem I need to solve with some unix utils

Jun 19, 2022
Reaction score
I'm the technical guy for a domain that is owned by people who are very creative but have no coding skills at all. I've been doing this on a volunteer basis now for 22 years. A long time ago, I taught the owners about server side includes. This allowed them to create a menu that appears on many of the 3800 pages they have but, if they make a change, they only have to change one file.

Somewhere along the way, the owners bought one of those fancy webpage coding apps and started using it. Apparently, it did not understand server side includes, so it change this code, which works: <!--#include virtual="../../includes/navigate_stack.html" --> to this code, which obviously will never work: <object data="../../includes/navigate_stack.html" type="text/html" width="230px" height="850px">.

There are 1182 pages with this code on them, so obviously I don't want to edit 1182 pages manually. Thus my problem.

I understand I can use sed to replace text on a page, and the beginning of the line is easy:
sed -i 's/<object data/<!--# include virtual/g' < input_files

The ends of the strings are quite different in the various pages but follow a consistent pattern:

/var/www/html/features/events/bc/jan08/index.html: <object data="../../../../includes/navigate_stack.html" type="text/html" width="230px" height="850px"></object>

/var/www/html/features/events/bc/jan08/index.html: <object data="../../../../includes/ads/5.html" type="text/html" width="230px" height="370px"></object>

/var/www/html/features/events/homecoming2008/index.html: <object data="../../../includes/1.html" type="text/html" width="230px" height="425px"></object>

/var/www/html/features/events/kansascity2007/index.html:<object data="../../../includes/4.html" type="text/html" width="230px" height="250px"></object>

/var/www/html/features/feature_stories/fitzgerald/back/index.html: <object data="../../../../includes/3.html" type="text/html" width="230px" height="350px"></object>

So, would something like this work?

sed -i 's/type=(some sort of regex to cover the rest)/-->/g'

I don't mind a bit of manual work (like running a shell script in one directory at a time), but I don't want to individually edit 1182 files.
Last edited:


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question