[GRASS-dev] v.in.gpsbabel nearly fixed: awk magic needed (RT bug#5478)

Patton, Eric epatton at nrcan.gc.ca
Thu May 10 18:45:36 EDT 2007


How about this?

head -2 Markus.txt | awk -F'\t' '{
if($3 == ""){$3 = "NULL"}
if($4 == ""){$4 = "NULL"}
if($6 == ""){$6 = "NULL"}
if($7 == ""}{$7 = "NULL"}

printf("echo \"INSERT INTO $NAME VALUES (%d, ^%s^, %s, %s, ^%s^, %s, %s)\" | db.execute\n", $1, $2, $3, $4, $5, $6, $7) }' | tr '^' \'

;)

~ Eric.

-----Original Message-----
From: grass-dev-bounces at grass.itc.it on behalf of Markus Neteler
Sent: Thu 5/10/2007 6:00 PM
To: GRASS developers list
Cc: grass-bugs at intevation.de
Subject: [GRASS-dev] v.in.gpsbabel nearly fixed: awk magic needed (RT bug#5478)
 
HI,

I think I got v.in.gpsbabel for tracks and routes (did that
ever work?). However, I have a final problem which requires
a bit of awk magic:

The GPX tracks file extracted from my Garmin contains a track
which isn't attributed (I dunno why but that's life). The
v.in.gpsbabel scripts successfully creates the map, then fails
on creating the attrib table. Here the problem:


# note: files contains tab delimiters
head -2 12021.0.track_atts
1
2               45.417394638    10.847196579            45.359029770    10.166580677


# make tab delim visible (just for illustration):
head -2 12021.0.track_atts | tr -s '\t' '|'
1 | | | | | |
2 | |45.417394638 |10.847196579 | |45.359029770 |10.166580677


# this is what happens in v.in.gpsbabel (note: it does cat instead of head):
head -2 12021.0.track_atts | awk -F'\t' '{ printf("echo \"INSERT INTO $NAME VALUES (%d, ^%s^, %s, %s, ^%s^, %s, %s)\" | db.execute\n", $1, $2, $3, $4, $5, $6, $7) }' | tr '^' \'
echo "INSERT INTO $NAME VALUES (1, ' ',  ,  , ' ',  , )" | db.execute
echo "INSERT INTO $NAME VALUES (2, ' ', 45.417394638 , 10.847196579 , ' ', 45.359029770 , 10.166580677)" | db.execute


We see that the first line isn't valid SQL. The first line should be:
echo "INSERT INTO $NAME VALUES (1, ' ', NULL  , NULL , ' ', NULL , NULL)" | db.execute

Question: what to ask in the awk line to autoinsert NULL if 0 length is
found in the numeric columns 3, 4, 6, 7?

thanks
Markus

_______________________________________________
grass-dev mailing list
grass-dev at grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev





More information about the grass-dev mailing list