Solved

many rows to one row :-)

Posted on 1998-07-02
9
188 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sort hash by values desc 2 193
crawling gofundme 4 126
grep that displays 4 lines above & 1 line below of what's found 10 80
iSeries PERL Scripts 7 157
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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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