Solved

Perl Grep  - print multiple occurances in same line ?

Posted on 2009-04-04
4
1,109 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

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
Regular Expression question to filter with negation. 6 89
sameEnds challenge 3 133
wordmultiple challenge 12 116
"Black Box" Testing of Control System Software 2 17
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

947 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

22 Experts available now in Live!

Get 1:1 Help Now