我在 plan9port 环境 shell 中编写了这个,但它很容易移植到任何 linux。
这段代码创建了一个 sed 脚本来旋转您的数据。
#!/usr/local/plan9/bin/rc
# .style1:color:#FFEFA1
cat > this.sed <<EOF
# for lines which start with .
/\./{
# strip open curly brace
s, {,:,
# store element tag
h
# skip to next line
n
}
# strip close curly brace
/}/d
# for other lines
{
# remove spaces
s, ,,g
# get rid of ; at end
s,;$,,g
# pull back in the element tag
G
# join to one line
s,\n,,
# shift element tag to the start
# sed in plan 9 is a little different
# for gnu sed, use \( \) and \+
s,(.*)(\.[^.]+$),\2\1,
# finally print something
p
}
EOF
这段代码针对 sed 脚本运行您的输入,
cat | sed -n -f this.sed <<EOF
.style1 {
font-size: 24px;
font-weight: bold;
color: #FFEFA1;
}
EOF
生成此输出。
.style1:font-size:24px
.style1:font-weight:bold
.style1:color:#FFEFA1
您可以 grep 查找您想要的行,或者“grep -v”您不想要的行。