Solved

closing html tags

Posted on 2004-04-02
4
174 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
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now