Solved

closing html tags

Posted on 2004-04-02
4
212 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 25 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 25 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

687 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