1871:1 0.00% http://example.org/filepath1
1872:1 0.00% http://example.org/filepath2
1873:1 0.00% http://example.org/filepath3
1877:1 0.00% http://example.org/filepath4
...etc
How can I extract the 3rd argument (the URL)
Thx!
[edited by: tedster at 6:55 am (utc) on July 12, 2008]
[edit reason] remove specific urls [/edit]
Something like this should do it:
#!/usr/bin/perl
# open the file
open (FILE,"yourfile.txt") or die("Cannot open file for reading $!");
# chomp newline, read line by line
while (chomp($line = <FILE>)) {
# split line on spaces
($id,$percent,$url) = split(/\s/,$line);
# You could do a number of things here, let's do two:
# print the variables and store URL's in an array (hash)
print "ID: $id PERCENT: $percent URL: $url\n";
$urls{$id} = $url;
}
#close file
close(FILE);
#print out contents of list
foreach $v (sort keys %urls) {
print "key: $v value: $urls{$v}\n";
}
2020:1 0.00%
You can use unpack() to extract the URLs, it is way more efficient than using split or other regexp. See the pack/unpack functions for details, or the pack/unpack tutorial that comes with perl.
If they are not fixed-length, use split() as shown by rocknbil.