diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
| commit | 6fae25b305d714b3ab7608fa003f1af9bf024545 (patch) | |
| tree | 05507b2c0505659d2fd847ecce988dacab63a236 /tools/csv/csv.move_column | |
| parent | 41ad31a2dee9ff912f222652f022b4c55cddcbf7 (diff) | |
Rename tools into bin
Diffstat (limited to 'tools/csv/csv.move_column')
| -rwxr-xr-x | tools/csv/csv.move_column | 18 |
1 files changed, 0 insertions, 18 deletions
diff --git a/tools/csv/csv.move_column b/tools/csv/csv.move_column deleted file mode 100755 index a62701f..0000000 --- a/tools/csv/csv.move_column +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 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' | ||