Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML and Perl

Posted on 2002-06-03
6
Medium Priority
?
177 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 85

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 85

Accepted Solution

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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

971 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