Solved

Perl Grep  - print multiple occurances in same line ?

Posted on 2009-04-04
4
1,112 Views
Last Modified: 2013-12-26

I am looking for a way to run

perl getreport > report.txt

and get a report that shows:
http://www.site1.com
http://www.site2.com
http://www.site3.com
http://www.site4.com

I have an input file - several hundred megs and am looking to print
any string between http:// and the '  symbol

some lines that strings occur multiple times.

Thank you,
Mark
blablablablablablablablablablablablablablabla
blablablahttp://www.site1.com'blablablablablablahttp://www.site2.com'blablablablablablablablabla
blablablablablablablablablablablablablablabla
blablablablablablablablablablablablablablabla
blablablahttp://www.site3.com'blablablablablablahttp://www.site4.com'blablablablablablablablabla
blablablablablablablablablablablablablablabla
blablablablablablablablablablablablablablabla
blablablablablablablablablablablablablablabla
blablablablablablablablablablablablablablabla

Open in new window

0
Comment
Question by:markpalinux
  • 3
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24070381
$\=$/;
$/="'';
@ARGV=("inputfile");
while( <> ){
  chomp;
  print $1if /http:(.+)/;
}
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24070417
#or
$\=$/;
@ARGV=("inputfile");
while( <> ){
  print for m#http://[^']+#g;
}
0
 
LVL 15

Author Comment

by:markpalinux
ID: 24077109
ozo,


I like the script in the second comment, the first had an error, I changed the qoutes. Then it returned
#
//www.site1.com
//www.site2.com
//www.site3.com
//www.site4.com


$\=$/;
$/="'";  # changed the qoutes here
@ARGV=("inputfile");
while( <> ){
  chomp;
  print $1if /http:(.+)/;
}


Thanks,
Mark
0
 
LVL 84

Expert Comment

by:ozo
ID: 24079973
$\=$/;
$/="'";  # changed the qoutes here
@ARGV=("inputfile");
while( <> ){
  chomp;
  print $1if /http:\/\/(.+)/;
}
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Line meaning 9 87
changeXy challenge 13 88
Thin secure Windows 10 5 102
Able to retrieve only 1 row through email amongst multiple rows 3 57
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

856 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