Created
July 23, 2018 08:49
-
-
Save vkudyushev/401e33f455645f30da8b31a2a2f1951b to your computer and use it in GitHub Desktop.
Combine json lines (from separate files) to (single) json array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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