My directory ~/foo
contains many HTML files. Each one has a different unwanted title
element. That is, each file contains the code
<title>something unwanted</title>
Many of these files also contain some span
elements like this
<span class="org-document-info-keyword">#+Title:</span>
<span class="org-document-title">correct title</span>
I'd like to write a script that scans each HTML file and, for each file that contains a code-block of the second type, replaces the unwanted title
with the correct title.
Once the title has been replaced, I'd like the script to remove the code in the second block.
For example, running the script on
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Created by htmlize-1.47 in css mode. -->
<html>
<head>
<title>foo.org</title>
<style type="text/css">
<!--
body {
color: #839496;
background-color: #002b36;
}
.org-document-info {
/* org-document-info */
color: #839496;
}
.org-document-info-keyword {
/* org-document-info-keyword */
color: #586e75;
}
.org-document-title {
/* org-document-title */
color: #93a1a1;
font-size: 130%;
font-weight: bold;
}
.org-level-1 {
/* org-level-1 */
color: #cb4b16;
font-size: 130%;
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
-->
</style>
</head>
<body>
<pre>
<span class="org-document-info-keyword">#+Title:</span> <span class="org-document-title">my desired title
</span><span class="org-document-info-keyword">#+Date:</span> <span class="org-document-info"><2015-08-23 Sun>
</span>
<span class="org-level-1">* hello world</span>
Vivamus id enim.
</pre>
</body>
</html>
should result in
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<!-- Created by htmlize-1.47 in css mode. -->
<html>
<head>
<title>my desired title</title>
<style type="text/css">
<!--
body {
color: #839496;
background-color: #002b36;
}
.org-document-info {
/* org-document-info */
color: #839496;
}
.org-document-info-keyword {
/* org-document-info-keyword */
color: #586e75;
}
.org-document-title {
/* org-document-title */
color: #93a1a1;
font-size: 130%;
font-weight: bold;
}
.org-level-1 {
/* org-level-1 */
color: #cb4b16;
font-size: 130%;
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
-->
</style>
</head>
<body>
<pre>
<span class="org-document-info-keyword">#+Date:</span> <span class="org-document-info"><2015-08-23 Sun>
</span>
<span class="org-level-1">* hello world</span>
Vivamus id enim.
</pre>
</body>
</html>
Is there a tool in linux that can easily do this?