Solved

many rows to one row :-)

Posted on 1998-07-02
9
212 Views
Last Modified: 2010-03-04
I need to have all text beetween:
<url  and </url> to be in one long row.. Any simple perl solution?
0
Comment
Question by:nifer
[X]
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
  • 5
  • 4
9 Comments
 

Author Comment

by:nifer
ID: 1208268
Edited text of question
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208269
When you say "in one long row" do you mean there are now multiple lines inside the <url> tags and you want a single line?

And what is "<url>" used for? I don't recognize that tag.
0
 

Author Comment

by:nifer
ID: 1208270
Yes there could be multiple lines inside the <url> tag, but not allways.

<url> are just some thing I use to make some splits later..




0
Technology Partners: 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!

 
LVL 6

Accepted Solution

by:
alamo earned 80 total points
ID: 1208271
Here's how'd I do it. The string is in $str.

local($s);
$str =~ s!(<url>.*?</url>)!{($s=$1)=~s/\n+/ /sg; $s;}!segi;

To explain it a little: this is a substitution inside a substitution. The outer subsitution is

$str =~ s!(<url>.*?</url>)!{expression}!segi;

where $1 is set to each <url> tag in turn and then replaced by the string produced by the expression evaluated in the {}.

The inner substitution copies $s to $1 (since $1 is read-only) and then does
s/\n+/ /sg;
which replaces one or more \n's with a space, thus combining the text into a single line.

Hope this does what you want!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208272
Umm, should be "copies $1 to $s" not "copies $s to $1" in my description.
0
 

Author Comment

by:nifer
ID: 1208273
And if i want it to be a simple script let say:

scriptname textfile > textfile2
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208274
Piece of cake, perl is cool:-)

$str = join('',<>);
local($s);
$str =~ s!(<url>.*?</url>)!{($s=$1)=~s/\n+/ /sg; $s;}!segi;
print $str;
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208275
Of course if you are on a unix-like system, you'll need to include a first line of something like

#!/bin/perl

so it knows to run perl.
0
 

Author Comment

by:nifer
ID: 1208276
worked well ;-)
0

Featured Post

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.

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

615 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