Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Created March 31, 2020 15:53
Show Gist options
  • Save dwallraff/b53c30ed1cf671b914dc1e6829e0a02c to your computer and use it in GitHub Desktop.
Save dwallraff/b53c30ed1cf671b914dc1e6829e0a02c to your computer and use it in GitHub Desktop.
loop to upload flat text files to wtf
#!/usr/bin/env bash
for i in *.yml; do
WORD=$(head -n 1 "$i")
ENCODED_WORD=$(echo -ne "$WORD" | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g')
DEF=$(tail -n+2 "$i" | awk '{printf "%s\\n", $0}')
echo "Posting $WORD..."
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"def" : "'"$DEF"'"}' \
"http://wtf.eng.<COMPANY>.com/api/def/add/?word=$ENCODED_WORD&def="
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment