无效字符 ' ' '在表达中

发布于 2024-11-17 19:32:25 字数 1316 浏览 5 评论 0原文

你好,我有以下 awk 程序

问题是我不知道为什么它在第 3 行抱怨 “awk ' invalid char ' ' ' in expression ” 当我执行 awk -f make.awk info.txt 时,

你们中的任何人在这个领域比我更聪明? =)

#!/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

Hi I have the following awk program

Problem is that I don't know why it complains on line 3
"awk ' invalid char ' ' ' in expression " when I do awk -f make.awk info.txt

Anyone of you out there who are brighter than me in this area? =)

#!/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-11-24 19:32:25

那不是 awk 程序,而是 bash 脚本。要运行它,请执行

chmod +x yourscript

以下操作

./yourscript parameters

That's not an awk program, but a bash script. To run it, do

chmod +x yourscript

and then

./yourscript parameters
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文