diff options
| author | typebrook <typebrook@gmail.com> | 2019-11-17 09:18:07 +0800 |
|---|---|---|
| committer | typebrook <typebrook@gmail.com> | 2019-11-17 09:18:07 +0800 |
| commit | 1d3508f66fddf3f8c6416e59ab9fbde405dbcf25 (patch) | |
| tree | 4f703dfa01596c133a4898c88fe837b8971e47e1 /scripts/csv/csv.reorder | |
| parent | e0673805fc648d47eadf5c76b822ccef5780d241 (diff) | |
update
Diffstat (limited to 'scripts/csv/csv.reorder')
| -rwxr-xr-x | scripts/csv/csv.reorder | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/csv/csv.reorder b/scripts/csv/csv.reorder new file mode 100755 index 0000000..df928f1 --- /dev/null +++ b/scripts/csv/csv.reorder | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | # show each field with index in csv | ||
| 4 | echo -------------- > /dev/tty | ||
| 5 | head -1 < $1 | awk -F',' '{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 "type column numbers by new order, like 3 2 1: " order | ||
| 11 | |||
| 12 | arrange=$(echo $order | sed -r 's/([^ ]+)/$\1/g' | tr ' ' ',') | ||
| 13 | |||
| 14 | cat $1 |\ | ||
| 15 | awk -F',' "BEGIN{OFS=\",\"}{print $arrange}" |\ | ||
| 16 | tee /tmp/csv |\ | ||
| 17 | echo "Also copied to /tmp/csv" > /dev/tty | ||
| 18 | |||
| 19 | |||