Skip to content

Instantly share code, notes, and snippets.

@vkudyushev
Created July 23, 2018 08:49
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 vkudyushev/401e33f455645f30da8b31a2a2f1951b to your computer and use it in GitHub Desktop.
Save vkudyushev/401e33f455645f30da8b31a2a2f1951b to your computer and use it in GitHub Desktop.
Combine json lines (from separate files) to (single) json array
#!/bin/bash
shopt -s nullglob
declare -a jsons
jsons=(*.json) # ${jsons[@]} - в переменной jsons теперь список всех файлов
echo '[' > combined.json
if [ ${#jsons[@]} -gt 0 ]; then # проверяем что список не пустой
cat "${jsons[0]}" >> manifest.json # первый файл в файл выхода
unset jsons[0] # и убираем из спика
for f in "${jsons[@]}"; do # и циклом по оставшимся
echo "," >>manifest.json
cat "$f" >>manifest.json
done
fi
echo ']' >>manifest.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment