Skip to content

Instantly share code, notes, and snippets.

@SteveViss
Created April 19, 2014 23:07
Show Gist options
  • Save SteveViss/11100333 to your computer and use it in GitHub Desktop.
Save SteveViss/11100333 to your computer and use it in GitHub Desktop.
Post traitment on climate data from NRCan using ANUSPLIN
#!/bin/bash
echo -n "Export folder empty or full (yes or no) ? "
read POST
echo -n "Import on remote or local server? "
read CON
TRAIT=~/Documents/QUICC_FOR/Climat_data_trait/
EXPORT=~/Documents/QUICC_FOR/Climat_data_trait/Export_climat
if [ "$POST" = "yes" ]; then
rm -R $EXPORT
cd $TRAIT
mkdir -vp $EXPORT
cd ./pntgrids
for i in $( ls ); do
cd $i
echo "Path:" `pwd`
echo "Unzip txt file in folder:" $i
gzip -dkf *.txt.gz
awk -v yr=$i '{$(NF+1)= yr}1' OFS='|' out$i.txt > $EXPORT/format$i.csv
cd ..
done
fi
echo "Import text file in Postgres..."
if [ "$CON" = "remote" ]; then
for file in $EXPORT/*; do
echo $file
cat $file | psql -U vissst01 -h srbd04.uqar.ca -d db_quicc_for -c "\copy rdb_quicc.climatic_data FROM stdin WITH DELIMITER AS '|' CSV HEADER;"
done
fi
if [ "$CON" = "local" ]; then
for file in $EXPORT/*; do
echo $file
cat $file | psql -U postgres -h localhost -p 5433 -d QUICC-FOR-Dev -c "\copy rdb_quicc.climatic_data FROM stdin WITH DELIMITER AS '|' CSV HEADER;"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment