diff options
Diffstat (limited to 'tools/csv.move_column')
-rwxr-xr-x | tools/csv.move_column | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/csv.move_column b/tools/csv.move_column new file mode 100755 index 0000000..a62701f --- /dev/null +++ b/tools/csv.move_column | |||
@@ -0,0 +1,18 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | # show each field with index in csv | ||
4 | echo -------------- > /dev/tty | ||
5 | head -1 < $1 | sed 's/,/ /g' | awk '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty | ||
6 | echo -------------- > /dev/tty | ||
7 | echo > /dev/tty | ||
8 | |||
9 | # get index of lon/lat column | ||
10 | read -p "Move which column? " origin_col | ||
11 | read -p "To which index? " new_col | ||
12 | |||
13 | cat $1 | | ||
14 | # move lon and lat to the first and second column | ||
15 | awk -F',' -v OFS="," -v origin_th=$origin_col -v new_th=$new_col '\ | ||
16 | {for (i=1; i<= NF; i++) if (i == new_th) printf $origin_th OFS $i OFS; else if (i == origin_th); else printf $i OFS; print ""}\ | ||
17 | ' |\ | ||
18 | sed 's/,$//g' | ||