Open 13o4t opened 6 years ago
前来膜拜大佬
Make it more readable and it can run on in Mac. I hate sed in mac
echo '<a>123<b>456<c/></b></a>' | \
# > to >\n
awk -F '>' '{for(i=1;i<NF;++i)print $i">"}' | \
# </ to \n</
sed -E $'s/([[:alnum:]_])</\\1\\\n</g' | \
awk '
BEGIN {level = 0}
{
if (substr($0,1,2) == "</") {
level--;
};
for(i=0;i<level;++i) {
printf "\t";
}
print $0
if (substr($0,1,1) == "<" && substr($0,2,1) != "/" && index($0,"/") != length($0)-1) {
level++;
}
}'
瑟瑟发抖
瑟瑟发抖
不会shell的就看看不说话
肛道理你们不能假设内容里面没有<
, >
这两个符号啊。
Question_ID: Q001
Language: Shell
Time Cost: 60-mins
Time Complexity: O(n)
Solution
My Code
Other
环境
Ubuntu 16.04