Reputation: 2318
In my question about sorting CSV files that you can view here: https://stackoverflow.com/a/31290947/2169327
I got an excellent answer from @fedorqui, which gave me the following code. It essentially just prints the values matching the coordinates into a new file.
#!/bin/sh
for f in *.out
do
awk -v lat=4 -v lon=3 -v min="69.41 70.39 70.71 69.556 69.8803 68.331146 68.049419 66.871467 68.148436 66.759238 66.175181 65.726251 65.786299 64.890885 62.650539 62.941216 62.785686 62.022545 62.149117 60.813038 59.374231" -v max="70.95 70.86 70.82 72.077 70.370 68.569232 68.241632 72.914490 69.42632 66.870346 66.412593 68.192098 66.001679 65.020729 62.997386 63.098843 62.860798 62.397420 62.388112 61.436394 59.67407" -v minl="27.72 27.69 29.66 13.767 22.3378 16.672046 16.032543 -2.105297 12.237355 13.557573 12.804985 3.572425 12.784130 11.117421 7.916285 7.627894 7.002356 5.977076 5.509247 5.845801 6.037732" -v maxl="28.416 28.73 29.98 23.117 23.7166 17.817370 16.539288 18.043629 15.188618 14.058137 14.329339 13.240394 13.260662 11.632093 8.627650 8.037134 7.250579 7.363814 6.193359 7.963416 6.425000" '
BEGIN {FS=OFS=";"; n=split(min,minlat," "); m=split(max,maxlat," "); h=split(minl, minlong," "); j=split(maxl,maxlong," ")}
{NF--;
for (i=1;i<=n;i++) {
if ($lat>=minlat[i] && $lat<=maxlat[i] && $lon>=minlong[i] && $lon<=maxlong[i])
{print; next}
}
}' $f > ${f%.*}.txt
echo ${f%.*}.txt
done
However, I would really really like to substitute all the commas with points in the same function (as in the outfile). This is because SQLite, where these data is going to be stored, accepts point as decimal point instead of comma.
This is my current example output:
27;2594800;22,35;70,24;14,50;98,00;1391212800;
31;2598;18,76;69,56;230,20;235,00;1391212800;
34;258500;16,58;69,70;18,20;201,00;1391212800;
27;231711000;22,42;70,27;99,20;99,00;1391212800;
Upvotes: 0
Views: 642
Reputation: 204311
The problem is that you're in a locale that uses ,
as the decimal point. Just change your locale, e.g.:
LC_ALL="C" awk '...'
and the problem will go away.
Upvotes: 1
Reputation: 2318
I found how I would do it:
sub(",",".",$lat);
sub(",",".",$lon);
If I want to substitute any more inputs I just have to define:
awk -v newSubstituteplace=2
sub(",",".",$newSubstituteplace);
To edit all inputs I have to do the following:
gsub(",",".")
See the comments below for the source of this, and please give the upvotes to them for helping me.
Upvotes: 1