Solved

many rows to one row :-)

Posted on 1998-07-02
9
182 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL Web Database 5 111
How to strip .csv from file name 9 78
Having a problem with ActiveState Perl on 64-bit Windows 7 3 68
ppm conversion to curl on a module install 8 80
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 …
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…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

14 Experts available now in Live!

Get 1:1 Help Now