| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
This is a commented version of the same with slight modifications and might be of help
of others....
# cat lg.sh
CSV='input.csv';
debug='0'; # controls the color me red (CMR) flag
url='https://maps.googleapis.com/maps/api/geocode/json?address=';
perl -Mvars='$URL,$CMR' -wMstrict -F'/;/' -spale '
push @F, map "", 1 .. 8-@F if @F < 8;
# increase fields to 8 only in case they are less
#--------0------------1---------2---------3---------4--------- --5-------6--7--
# firstname; lastname; adress; town; country; Goog_add; lt; lg
# skip when address/town/country all are empty or
# also skip when google-address, latitiude, longitude are filled up already
next if "@F[2..4]" =~ /^\s+$/ or "@F[5..7]" =~ /\S/;
# whitespace -> plus sign in order to string the google search argument
y/ \t/++/ for my $i = join "", @F[2..4];
# run the curl command on the url with the current address/town/country
chomp(my @curl = qx[curl -s "$URL/$i"]);
# extract the contents (google address/latitude/longitude) from the curl output
my ($content) = (
join(";",
map {
($_) = /[:]\s+(.+?)[,]?\s*$/; # this regex influenced by the fmt of the google search o/p
/"(.*)"/ ? $1 : $_
}
grep {
m?lat? or m?lng? or m?formatted_address?
}
@curl
),
reset()
);
$content =~ s/(.*)/\e[31m$1\e[0m/ if $CMR; # Color_Me_Red
# put the results of curl into the csv input
$_ = join ";", @F[0..4], $content;
' -- -URL="$url" -CMR="${debug:-0}" "$CSV"
> From: MOKRANI Rachid <[email protected]>
> Sent: Wednesday, January 20, 2016 7:19 AM
> Subject: RE: loop
>
> Hi Rakesh,
>
> Thanks a lots for all.
>
> Have a nice day.
>
>
>> -----Message d'origine-----
>> De : [email protected] [mailto:[email protected]]
>> Envoyé : mercredi 20 janvier 2016 08:16
>> À : [email protected]
>> Objet : Re: loop
>>
>>
>>
>>
>> # cat lg.plx
>> url='https://maps.googleapis.com/maps/api/geocode/json?address='
>>
>>
>> CSV='input.csv'
>>
>>
>> perl -Mvars='$URL,@F' -wMstrict -sple '
>> @F = split /;/, $_, 8; # ensure line has exactly eight fields
>>
>>
>> # Index
>> # 0 1 2 3 4 5 6 7
>> # firstname;lastname;adress;town;country;Goog_add;lt;lg
>>
>>
>>
>> # skip non-interesting lines
>> next if "@F[2..4]" =~ /^\s+$/ or "@F[5..7]" =~ /\S/;
>>
>>
>> y/ /+/ for my $i = join "", @F[2..4];
>>
>>
>> chomp(my @curl = qx{curl -s "$URL/$i"});
>>
>>
>> my $content = do{reset;
>> join(";",
>> map {
>> ($_) = /[:]\s+(.+?)[,]?\s*$/;
>> /"(.*)"/ ? $1 : $_
>> }
>> grep {
>> m?lat? or m?lng? or m?formatted_address?
>> }
>> @curl
>> )};
>>
>> $_ = join( ";", @F[0..4], "\e[31m$content\e[0m" );
>>
>>
>>
>> ' -- -URL="$url" "$CSV"
>>
>>
>>
>>
>> HTH
>> -Rakesh
[Non-text portions of this message have been removed]