Created
March 6, 2018 09:12
-
-
Save nanpuyue/62d19f28538d30515b2ae33c83139751 to your computer and use it in GitHub Desktop.
格式化输出数组
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 | |
# date: 2018-03-06 | |
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
# author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com | |
P='NONE' | |
sed -r 's/,/,\n/g;s/\{/\n\{\n/g;s/\}/\n\}/g'|grep -Pv "^\s*$"|\ | |
while read line; do | |
if [[ "$line" =~ \{ ]];then | |
[[ "$P" = 'NONE' ]] && P='' || P+='\t' | |
echo -e "${P}${line}" | |
elif [[ "$line" =~ \} ]];then | |
echo -e "${P}${line}" | |
P=${P/\\t/} | |
else | |
echo -e "${P}${line}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment