Solved

Perl Grep  - print multiple occurances in same line ?

Posted on 2009-04-04
4
1,114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NotAlone Challenge 20 93
Problem to open Excel file 15 266
Way to decrease size of apk file 9 132
Authenticate using sesu from script 7 159
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…
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.
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.

739 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