Solved

Perl Grep  - print multiple occurances in same line ?

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

746 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

8 Experts available now in Live!

Get 1:1 Help Now