Solved

Perl Grep  - print multiple occurances in same line ?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 91
matchUp  challenge 9 123
How to convert MFC::CString to UTF8 wchar_t* 10 364
Perl: How to add backslashes to every period in a string 1 49
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…

685 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