Skip to content

Instantly share code, notes, and snippets.

@samerickson
Created February 2, 2021 05:37
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 samerickson/cf95e77c505f963531da40bc9f32ecfb to your computer and use it in GitHub Desktop.
Save samerickson/cf95e77c505f963531da40bc9f32ecfb to your computer and use it in GitHub Desktop.
# This file allows you to combine multiple json files into one
# Just pass all the paths to all the files you want to combine using
# command line arguments
FILES=$@
TMP_FILE="/tmp/results.tmp"
RESULT_FILE=results.json
echo "${FILES}"
echo "[" > "${TMP_FILE}"
for FILE in "${FILES}"; do
SET="$(cat ${FILE} | sed 's/^/ /g')"
# ISSUE: should not add trailing comma on last entry
printf "${SET},\n" | sed 's/}{/},\n {/g' >> "${TMP_FILE}"
done
echo "]" >> "${TMP_FILE}"
sed 'x;${s/,$//;p;x;};1d' ${TMP_FILE} > "${RESULT_FILE}"
rm /tmp/results.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment