in reply to Re: Extract part of string and remove the rest
in thread Extract part of string and remove the rest

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

Replies are listed 'Best First'.
Re^3: Extract part of string and remove the rest
by puudeli (Pilgrim) on Feb 19, 2009 at 14:02 UTC

    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};