Solved

HTML and Perl

Posted on 2002-06-03
6
171 Views
Last Modified: 2010-05-18
I would like to make a copy of everything between the tag <title> and </title> and place it at the start of the opening body tag.  


Orginal file:
<html>

<head>


<title> This is my Web page

Please sign my guess book
</title>



<head>

<body>
The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>


Should look like this:

<html>

<head>


<title> This is my Web page

        Please sign my guess book
</title>



<head>

<body>
This is my Web page.

Please sign my guess book.

The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>

0
Comment
Question by:kennybud416
  • 4
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7051893
s/(<title>(.*?)<\/title>.*?<body>)/$1\n$2/si;
0
 

Author Comment

by:kennybud416
ID: 7051962
can I run this from the command line? How do I specify the file name?
0
 

Author Comment

by:kennybud416
ID: 7052011
When I run the script is I get no out put?  I tried adding the line s/(<title>(.*?)<\/title>.*?<body>)/$1\n$2/si;print; to the end but it didn't display anything.

How would I specify the file name? What does the /si syntax mean?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:kennybud416
ID: 7052057
I have modified the script to look like this.perl -ane 's/(<title>(.*?)<\/title>.*?<body>)/$1\n$2/si;print;' 200206013032.xml

but it doesn't do any thing to the actual file? Am I doing something wrong?
0
 

Author Comment

by:kennybud416
ID: 7052150
Will the script still work .If the text in between the title tags are on more than one line?
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7052159
perl -0777i.bak -pe 's/(<title>(.*?)<\/title>.*?<body>)/$1\n$2/si' 200206013032.xml
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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