Reputation:
I have a .CSV file with the following entries. The last entry is location.
I wish to extract the latitude and longitude out of it without doing it manually. Can anyone suggest a way of doing it ? Please help.
The 1st 2 entries are :
"Type","LicenseNumber","Name","Building","StreetName","Location","City","State","Zip","Tel","Loc"
"ELECTRONICS STORE",800057,"CAMERA LAND INC",575,"LEXINGTON AVENUE",,"NEW YORK","NY",10022,2127535128,"LEXINGTON AVENUE
NEW YORK, NY 10022
(40.7588057463651, -73.9680023077056)"
Upvotes: 1
Views: 419
Reputation: 4431
Here is the java library you want to use perhaps http://sourceforge.net/projects/libcsv/ and another library http://opencsv.sourceforge.net/ and lastly use split("\,") http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String) to get to your longitude,latitude.
hope it helps
Upvotes: 1
Reputation: 7124
You could use any programming language with regular expressions. Perl example below.
Save following to a script
#!/usr/bin/perl -w
use strict;
while ( my $line = <> ) {
#match paretheses, followed by a number, followed by comma, followed by optional space, followed by number, followed by paretheses, followed by end of line
if ( $line =~ /\((-?\d+\.\d+), ?(-?\d+\.\d+)\)"$/ ) {
print "Latitude: $1, Longitude: $2\n";
}
else {
print "expression not found in line $.\n";
}
}
and run it on CSV file.
$ perl my_script.pl my_file.csv
Upvotes: 1