MOKRANI Rachid rachid.mokrani@ifpen.fr [sed-users]
2016-01-19 16:14:11 UTC
Hi,
From an address file I would add the lat and long in this file.
Some conditions must be respected in the script.
It is important not to execute and don't try the script on the lines which the town AND country AND adress fields are empty
AND
Do not execute or try the script on the lines which lat and long value has already been registered.
# cat input.csv
firstname;lastname;adress;town;country;Goog_add;lt;lg
first1;lastname1;81 Kensington Gardens Square;london;uk;;;
firts2;lastname2;;;;;;
firts3;lastname3;14 cleveland row saint james;london;uk;14 Cleveland Row, St. James's, London SW1A 1DH, Royaume-Uni;51.5037514;-0.1397412
firts4;lastname4;4301-4399 3rd avenue brooklyn;New York;USA;4301-4399 3rd Ave, Brooklyn, NY 11220, USA;40.651233;-74.010647
firts5;lastname5;;;;;;
firts6;lastname6;place de la bastille;paris;france;;;
With the script below I can obtain an outcome, but it is insufficient.
# cat lg.sh
url="https://maps.googleapis.com/maps/api/geocode/json?address="
for i in $( awk -F ";" ' NR==1{next} {print $3 $4 $5 }' input.csv | egrep -o "[^,]+" | sed 's/\,$//g' | sed 's/\,/\, /g' | sed 's/[ ]/+/g' ) ; do
content="$(curl -s "$url/$i" | grep -m3 -E 'lat|lng|formatted_address' | sed "s/.*/;&/" | xargs | sed 's/formatted_address ://g' )"
echo -e "$content"
done
; 81 Kensington Gardens Square, London W2 4DJ, UK, ; lat : 51.5140226, ; lng : -0.1892987
; 14 Cleveland Row, St. James's, London SW1A 1DH, UK, ; lat : 51.5042408, ; lng : -0.1398204
; 4399 3rd Ave, Brooklyn, NY 11220, USA, ; lat : 40.6454789, ; lng : -74.01718509999999
; Place de la Bastille, Paris, France, ; lat : 48.8538045, ; lng : 2.3705269
I need the following output
cat input.csv
firstname;lastname;adress;town;country;Goog_add;lt;lg
first1;lastname1;81 Kensington Gardens Square;london;uk;81 Kensington Gardens Square, London W2 4DJ, UK, ;51.5140226;-0.1892987
firts2;lastname2;;;;;;
firts3;lastname3;14 cleveland row saint james;london;uk;14 Cleveland Row, St. James's, London SW1A 1DH, Royaume-Uni;51.5037514;-0.1397412
firts4;lastname4;4301-4399 3rd avenue brooklyn;New York;USA;4399 3rd Ave, Brooklyn, NY 11220, USA, ;40.6454789;-74.01718509999999
firts5;lastname5;;;;;;
firts6;lastname6;place de la bastille;paris;france;Place de la Bastille, Paris, France, ;48.8538045;2.3705269
Some help please.
Regards.
__________________________
Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing !
Ce message et toutes ses piÚces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message.
__________________________
[Non-text portions of this message have been removed]
From an address file I would add the lat and long in this file.
Some conditions must be respected in the script.
It is important not to execute and don't try the script on the lines which the town AND country AND adress fields are empty
AND
Do not execute or try the script on the lines which lat and long value has already been registered.
# cat input.csv
firstname;lastname;adress;town;country;Goog_add;lt;lg
first1;lastname1;81 Kensington Gardens Square;london;uk;;;
firts2;lastname2;;;;;;
firts3;lastname3;14 cleveland row saint james;london;uk;14 Cleveland Row, St. James's, London SW1A 1DH, Royaume-Uni;51.5037514;-0.1397412
firts4;lastname4;4301-4399 3rd avenue brooklyn;New York;USA;4301-4399 3rd Ave, Brooklyn, NY 11220, USA;40.651233;-74.010647
firts5;lastname5;;;;;;
firts6;lastname6;place de la bastille;paris;france;;;
With the script below I can obtain an outcome, but it is insufficient.
# cat lg.sh
url="https://maps.googleapis.com/maps/api/geocode/json?address="
for i in $( awk -F ";" ' NR==1{next} {print $3 $4 $5 }' input.csv | egrep -o "[^,]+" | sed 's/\,$//g' | sed 's/\,/\, /g' | sed 's/[ ]/+/g' ) ; do
content="$(curl -s "$url/$i" | grep -m3 -E 'lat|lng|formatted_address' | sed "s/.*/;&/" | xargs | sed 's/formatted_address ://g' )"
echo -e "$content"
done
; 81 Kensington Gardens Square, London W2 4DJ, UK, ; lat : 51.5140226, ; lng : -0.1892987
; 14 Cleveland Row, St. James's, London SW1A 1DH, UK, ; lat : 51.5042408, ; lng : -0.1398204
; 4399 3rd Ave, Brooklyn, NY 11220, USA, ; lat : 40.6454789, ; lng : -74.01718509999999
; Place de la Bastille, Paris, France, ; lat : 48.8538045, ; lng : 2.3705269
I need the following output
cat input.csv
firstname;lastname;adress;town;country;Goog_add;lt;lg
first1;lastname1;81 Kensington Gardens Square;london;uk;81 Kensington Gardens Square, London W2 4DJ, UK, ;51.5140226;-0.1892987
firts2;lastname2;;;;;;
firts3;lastname3;14 cleveland row saint james;london;uk;14 Cleveland Row, St. James's, London SW1A 1DH, Royaume-Uni;51.5037514;-0.1397412
firts4;lastname4;4301-4399 3rd avenue brooklyn;New York;USA;4399 3rd Ave, Brooklyn, NY 11220, USA, ;40.6454789;-74.01718509999999
firts5;lastname5;;;;;;
firts6;lastname6;place de la bastille;paris;france;Place de la Bastille, Paris, France, ;48.8538045;2.3705269
Some help please.
Regards.
__________________________
Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing !
Ce message et toutes ses piÚces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message.
__________________________
[Non-text portions of this message have been removed]