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
Solved

HTML and Perl

Posted on 2002-06-03
6
172 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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…

860 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