Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Created March 6, 2018 09:12
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 nanpuyue/62d19f28538d30515b2ae33c83139751 to your computer and use it in GitHub Desktop.
Save nanpuyue/62d19f28538d30515b2ae33c83139751 to your computer and use it in GitHub Desktop.
格式化输出数组
#!/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