我有这个脚本
#!/bin/bash
function labels2 () {
awk '
/[0-9]/{
print substr($3,length($3)-11), $3
}' $@ | /bin/sort -u | awk '{print "BUILD: " NR, $2}'
}
function labels () {
awk '
/[0-9]/{
BL[$3] = substr($3,length($3)-11)
}
END {
asort(BL)
for (i in BL) {
print i, BL[i]
}
}' $@
}
labels $@
exit 0
for a in $@
do
labels $@ | gawk '
/BUILD:/ {
BUILD[$2] = $3
BUILDCNT ++
next
}
/[0-9]/ {
DATEd[$3] = $1
TIMEd[$3] = $2
MODULESd[$3] = $4
CASESd[$3] = $5
FAILEDd[$3] = $6
COVERd[$3] = $7
LOCd[$3] = $8
}
END {
SUBSYSTEM=substr(FILENAME, 1, length(FILENAME)-7)
LABEL= "\"" toupper(SUBSYSTEM) "\""
print "{"
print "subsystem: " LABEL ","
print " date: {"
print " label: " LABEL ","
print " data: ["
for (i = 0 ; i <= BUILDCNT; i ++ ) {
B=BUILD[i]
if (DATEd[B]) { print " [" i ", \"" DATEd[B] "\"]," }
}
print " ]"
print " },"
}
' - $a
done
此文本输入文件cos.txt
2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399
2011-01-22 22:12 P16A22_110114072915 22 1312 75 13.55 1399
现在我的问题是,为什么打印出来
1 110114072915
2 110114072915
而不是
{
subsystem: "COS",
date: {
label: "CAS",
data: [[1,"110114072915"],[2,110114072915]]
}
修改------------------------------------------- -------------------------------------
我按照你们的说法做了,但它部分奏效了。但现在它来自表格
1 110114072915
2 110114072965{
subsystem: "COS",
date: {
label: "COS",
data: [
[0, "3"],
]
},
而不是表格
{
subsystem: "COS",
date: {
label: "CAS",
data: [[1,"110114072915"],[2,110114072915]]
}
我该怎么改变?我也想这样做,他们按顺序
数组中的=)
再次感谢您的帮助=)
答案 0 :(得分:1)
因为
labels $@
exit 0 <-- you told exit after the function "labels"... ;)