?
Solved

closing html tags

Posted on 2004-04-02
4
Medium Priority
?
215 Views
Last Modified: 2010-03-04
I  need a script that closes an open tag...However it must close a specific tag mutiple times.

Below I have the name tag, which needs to be closed through out the document.  Not just three times, but however many times it appears in a document.

<name>

<name>

<story>
story tag text
</story>

<name>



Should look like:


<name>
</name>
<name>
</name>
<story>
story tag text
</story>

<name>
</name>


FYI:
The script below skips the name tag if two appear in a row.  
perl -ape '/^\s*<name>/&&do{$h=1;next;};/^\s*</&&do{if ($h==1) {print "</name>\n";$h=0;}};'
0
Comment
Question by:kennybud416
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 10746602
perl -ape '/^\s*</&&do{if ($h==1) {print "</name>\n";$h=0;}};/^\s*<name>/&&do{$h=1;next;};'
0
 
LVL 3

Assisted Solution

by:PerlKing
PerlKing earned 100 total points
ID: 10755473
You assume that there would be only one <name> tag per line.  What if something like the following occurs?

<name> <name>
<name>
<story>
story text
</story>

Does this ever happen? If it does, the following code takes care of it,
perl -ape '/^\s*</ && do { if ($h==1) {print "</name>\n";$h=0;} }; /^\s*<name>/&&do{s/<name>(.*)</<name>$1</name></g; $h=1;next;};'
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question