dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29355
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14813: Adding script for preparing text for import as csv
------------------------------------------------------------
revno: 14813
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-04-12 19:18:38 +0200
message:
Adding script for preparing text for import as csv
added:
resources/util/prepare_csv.sh
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'resources/util/prepare_csv.sh'
--- resources/util/prepare_csv.sh 1970-01-01 00:00:00 +0000
+++ resources/util/prepare_csv.sh 2014-04-12 17:18:38 +0000
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+# Prepares list of names for import as CSV
+# Removes weird stuff and wraps in quotes
+# First argument is name of file
+
+# Replace tabs with white spaces
+
+sed -i 's/\t/ /g' $1
+
+# Remove multiple white spaces
+
+sed -i 's/ \{1,\}/ /g' $1
+
+# Delete empty lines
+
+sed -i '/^\s*$/d' $1
+
+# Remove spaces/tabs at beginning of lines
+
+sed -i 's/^\s+//g' $1
+
+# Remove spaces/tabs at end of lines
+
+sed -i 's/\s+$//g' $1
+
+# Remove dots at end of lines
+
+sed -i 's/\.$//g' $1
+
+# Remove "number of" variants
+
+sed -i 's/# of //g' $1
+sed -i 's/# Of //g' $1
+sed -i 's/# //g' $1
+sed -i 's/number of //g' $1
+sed -i 's/Number of //g' $1
+
+# Wrap in quotes
+
+sed -i 's/^.*$/"&"/g' $1
+
+# Insert header line
+
+sed -i '1s/^/name\n/' $1