{"comment":{"url":"https://api.github.com/repos/geometalab/osmaxx-postgis-conversion/comments/13368340","html_url":"https://github.com/geometalab/osmaxx-postgis-conversion/commit/ec553e1343c915c0430140c52d6a0e39974e0b39#commitcomment-13368340","id":13368340,"user":{"login":"wasabideveloper","id":10944699,"avatar_url":"https://avatars.githubusercontent.com/u/10944699?v=3","gravatar_id":"","url":"https://api.github.com/users/wasabideveloper","html_url":"https://github.com/wasabideveloper","followers_url":"https://api.github.com/users/wasabideveloper/followers","following_url":"https://api.github.com/users/wasabideveloper/following{/other_user}","gists_url":"https://api.github.com/users/wasabideveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/wasabideveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wasabideveloper/subscriptions","organizations_url":"https://api.github.com/users/wasabideveloper/orgs","repos_url":"https://api.github.com/users/wasabideveloper/repos","events_url":"https://api.github.com/users/wasabideveloper/events{/privacy}","received_events_url":"https://api.github.com/users/wasabideveloper/received_events","type":"User","site_admin":false},"position":1,"line":20,"path":"extract/extract/extract_statistics.sh","commit_id":"ec553e1343c915c0430140c52d6a0e39974e0b39","created_at":"2015-09-22T14:20:52Z","updated_at":"2015-09-22T14:20:52Z","body":"This file is full of repeated code. Is it possible to extract that code to a function an call the function instead?\r\n```shell\r\nextract_statistic_of_table(table, database, file) {\r\n\techo \"$1\" >> \"$3\"\r\n\tval=(admin_level1 national admin_level3 admin_level4 admin_level5 admin_level6 admin_level7 admin_level8 admin_level9 admin_level10 admin_level11 administrative national_park protected_area)\r\n\tfor val in ${val[@]}\r\n\tdo\r\n\t\tcount=$(psql -U postgres -Atc \"SELECT count(type) from osmaxx.$1 where type='\"$val\"' and osmaxx.$1.geom && ST_MakeEnvelope($XMIN, $YMIN, $XMAX, $YMAX, $CRS)\" $2)\r\n\t\tprintf \"%20s,%20s\\n\" $val\t$count>>TEMP.txt;\r\n\tdone\r\n\tsort --key=2 --reverse --numeric-sort TEMP.txt >> $3\r\n\trm TEMP.txt\r\n\techo >> $3\r\n}\r\n```\r\n```shell\r\nextract_statistic_of_table \"adminarea_a\" \"osmaxx_db\" \"$FILE\"\r\n```"}}