Solved

many rows to one row :-)

Posted on 1998-07-02
9
205 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PERL get the value for query 4 163
perl to display a matrix report for 3-dimenional array 3 75
stftime format 4 59
Perl script not writing to .csv file 6 125
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 …
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…

710 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