Skip to content

Instantly share code, notes, and snippets.

@lsheng
Created March 14, 2013 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsheng/5165799 to your computer and use it in GitHub Desktop.
Save lsheng/5165799 to your computer and use it in GitHub Desktop.
Script that generates a flat import descriptor based on the headers of a CSV
#!/bin/bash
# Generates a flat import descriptor based on the headers of a CSV
FILENAME=$1
if [ ! -e "$FILENAME" ]; then
echo "Could not find file: $FILENAME"
exit 1
fi
echo "{"
echo " name : \"default\","
echo " families : [ {"
echo " name : \"info\","
echo " columns : [ {"
# Loop over fields and put in the relevant description lines
FIRST=true
for x in `head -1 $FILENAME | tr -d '\r' | tr , '\n'`; do
if [ "$FIRST" != "true" ]; then
echo " }, {"
fi
echo " name : \"$x\","
echo " source : \"$x\""
FIRST=false
done
echo " } ]"
echo " } ],"
FIRSTFIELD=$(head -1 $FILENAME | sed -e "s/,.*//")
echo " entityIdSource : \"$FIRSTFIELD\","
echo " version : \"import-1.0\""
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment