Last active
December 21, 2024 01:42
-
-
Save sulincix/a58953e69cca96a612d6f0e8059a2af8 to your computer and use it in GitHub Desktop.
json formater in posix shell and just sed command
This file contains hidden or 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/sh | |
i=0 | |
sed \ | |
" | |
s/^ *//g | |
s/^\t*//g | |
s/,/,\n/g | |
s/{/\n&\n/g | |
s/}/\n&/g | |
s/\[/&\n/g | |
s/\]/\n&\n/g | |
" |while read line ; do | |
case "$line" in | |
"{") | |
i=$(expr $i + 1) | |
;; | |
esac | |
if [ $i -gt 1 ] ; then | |
j=0 | |
while [ $j -lt $i ] ; do | |
echo -n " " | |
j=$(expr $j + 1) | |
done | |
fi | |
case "$line" in | |
"}") | |
i=$(expr $i - 1) | |
;; | |
esac | |
echo $line | |
done | sed "/^$/d" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment