Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Extract part of string and remove the rest

by puudeli (Pilgrim)
on Feb 19, 2009 at 12:53 UTC ( [id://745027]=note: print w/replies, xml ) Need Help??


in reply to Extract part of string and remove the rest

Please see:

You should also give a more detailed description (eg. what lines do you want to capture and what do you want to remove?) and a sample code that fails to do what you want to do. That way monks can help you much more efficiently.

--
seek $her, $from, $everywhere if exists $true{love};

Replies are listed 'Best First'.
Re^2: Extract part of string and remove the rest
by sandy1028 (Sexton) on Feb 19, 2009 at 12:55 UTC
    Location: http://www.google.com Status Code: 200 OK <br /> File : http://www.aby.cos Status code: 500 Server Error
    I have to extract only http://www.google.com and http://www.aby.cos and remove the other text for the lines

      You could use split or regular expressions.

      perl -e '$s="Location: http://www.google.com Status Code: 200 OK"; @pc +s = split(/ /, $s); for ( @pcs ) { print $_ . "\n" if /http/; }'
      which produces
      http://www.google.com
      or
      #! /usr/bin/perl use strict; use warnings; my @hits; while( <DATA> ) { chomp; push @hits, $1 if $_ =~ /\w*(http:\S+)/; } print join("\n", @hits) . "\n"; 1; __DATA__ Location: http://www.google.com Status Code: 200 OK <br /> File : http://www.aby.cos Status code: 500 Server Error
      which produces
      http://www.google.com http://www.aby.cos
      --
      seek $her, $from, $everywhere if exists $true{love};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://745027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-26 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found