Help with regexp
Hi!
I have a html file with following data in it. <h3>Some title</h3><a name="something"></a> March 13 ... <h3>Some other title</h3><a name="something"></a> Feb 21 ... I want to replace such instances with <h3>Some title</h3><a name="March 13"></a> ... <h3>Some other title</h3><a name="Feb 21"></a> ... Is it possible? Perl/Pything/Shell anything is good. Shell is preferred. |
A pseudo code:
(1) If line begins with <h3>, then store it. (2) If previous line was <h3>, then store the date, and rewrite the <h3> line with changed url, and also write the current line. (3) else write the line. btw. whats the use? End |
To create a table of blog entries and uniquely name-reference them :)
The date is actually full "date -Ru" so for all practical purposes, it will be unique... |
Could you please tell me how to do it in perl? I don't remember it at all!
|
This does the trick for the first time.
Code:
cat blog.html|sed ':a;N;$!ba;s/<\/h3>\n[ \t]*/<\/h3>/g'|perl -p -e "s,<h3>.*</h3>,<a name=\"$'\"></a>$&\n,g" |
All times are GMT -5. The time now is 10:48 AM. |