Solved

HTML and Perl

Posted on 2002-06-03
6
170 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl script help 12 101
Exchange 2010 Transport Rule Regex 28 88
How to generate square thumbnail using perl 13 70
Perl Frameworks 1 56
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 …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

11 Experts available now in Live!

Get 1:1 Help Now