繁体   English   中英

awk数组模式不匹配

[英]awk array pattern not matching

这是我的Shell脚本

#!/bin/bash
# need this or can't process file names with spaces
OIFS="$IFS"
IFS=$'\n'
file_name=file_name.xlsx

# --re-interval or the repeat character {} will not work
python ./Enforcer/scripts/xlxstocsv.py -m -s 1 -d ';' $file_name | awk --re-interval -F ';' '
# list of all the CGIDs from the schema
BEGIN {split("EKM-04.3 EKM-03.1 AAC-02.5 DCS-02.1 BCR-11.1 IAM-13.2 HRS-01.1 IVS-03.1 TVM-02.5 IAM-10.1 DSI-01.4 DSI-03.1 DSI-05.1 AAC-02.6 IAM-04.1 BCR-11.2 IAM-13.3 GRM-06.2 IAM-01.1 AIS-01.2 DSI-02.2 IVS-07.1 SEF-02.1 BCR-05.1 EKM-03.3 AAC-02.7 AAC-03.2 IAM-11.1 HRS-03.1 GRM-01.1 AAC-03.1 HRS-08.2 IAM-08.1 AAC-02.3 DCS-07.1 AIS-02.1 AAC-03.3 IAM-11.2 BCR-11.4 SEF-04.3 EKM-02.1 SEF-03.1 DSI-07.1 BCR-10.1 BCR-06.1 AIS-03.1 HRS-04.1 DSI-01.7 IVS-01.2 IAM-06.1 BCR-11.5 SEF-04.4 SEF-03.2 DSI-07.2 AIS-01.5", schema_CGID) }
{
# 
if (match($3,/[A-Z]{2,3}-[0-9]{2}\.[0-9]/))
    {
# use the index to find the location of the patten
    let_it_be=index($3,substr($3,RSTART,RLENGTH))
# the CGID seems to USUALLY be in the first 30 spaces of the output
    if (let_it_be < 30) 
        {
        CGID=substr($3,RSTART,RLENGTH)
        { for (N=1; N<=NF; N++) {if (schema_CGID[$N] ~ CGID) {print "schema match ", $i} else  {print "no schema match for CGID [" CGID "] schema [" schema_CGID[$N] "]", $N}}}
        if (match(tolower($0),/yes|no/))
            {
            yes_no=substr($0,RSTART,RLENGTH)
            }
        else {yes_no="NA"}
            }
    foobar[CGID " " yes_no]
    }
}
# the sort is necessary for the output to be useful, as the array uses weird things and the order is lost
END{ for (var in foobar) print var | "sort"}'
#END{ for (var in foobar) print var }'
IFS="$OIFS"

我正在使用Python工具xlxstocsv.py处理XLSX(Excel电子表格)文件。 我(尝试)用这个字符串创建一个数组

BEGIN {split("EKM-04.3 EKM-03.1 AAC-02.5 DCS-02.1 BCR-11.1 IAM-13.2 HRS-01.1 IVS-03.1 TVM-02.5 IAM-10.1 DSI-01.4 DSI-03.1 DSI-05.1 AAC-02.6 IAM-04.1 BCR-11.2 IAM-13.3 GRM-06.2 IAM-01.1 AIS-01.2 DSI-02.2 IVS-07.1 SEF-02.1 BCR-05.1 EKM-03.3 AAC-02.7 AAC-03.2 IAM-11.1 HRS-03.1 GRM-01.1 AAC-03.1 HRS-08.2 IAM-08.1 AAC-02.3 DCS-07.1 AIS-02.1 AAC-03.3 IAM-11.2 BCR-11.4 SEF-04.3 EKM-02.1 SEF-03.1 DSI-07.1 BCR-10.1 BCR-06.1 AIS-03.1 HRS-04.1 DSI-01.7 IVS-01.2 IAM-06.1 BCR-11.5 SEF-04.4 SEF-03.2 DSI-07.2 AIS-01.5", schema_CGID)

我正在处理我的文件,但是,我想测试我成功找到的字符串是否在这个schema_CGID数组中我成功创建的变量是好的,我尝试了很多东西,但这是最接近的我明白了

我甚至可以看到一场比赛(第3行)!

no schema match for CGID [AIS-01.1] schema [] Application Security"
no schema match for CGID [AIS-01.1] schema [] AIS-01
no schema match for CGID [AIS-01.1] schema [] AIS-01.1
no schema match for CGID [AIS-01.1] schema [] Applications and programming interfaces (APIs) shall be designed, developed, deployed, and tested in accordance with leading industry standards (e.g., OWASP for web applications) and adhere to applicable legal, statutory, or regulatory compliance obligations.
no schema match for CGID [AIS-01.1] schema [] Do you use industry standards (Build Security in Maturity Model [BSIMM] benchmarks, Open Group ACS Trusted Technology Provider Framework, NIST, etc.) to build in security for your Systems/Software Development Lifecycle (SDLC)?
no schema match for CGID [AIS-01.1] schema [] Yes
no schema match for CGID [AIS-01.1] schema [] 
no schema match for CGID [AIS-01.1] schema [] 

为什么是我if不匹配我的阵列项目? schema_CGID[$N]的值似乎有效,但比较似乎失败了

TIA

split()默认使用FS值。 你将FS设置为; 在命令行上,但是您尝试拆分的字符串由空格分隔,因此结果数组schema_CGID只包含1个值 - 您尝试拆分的整个字符串。 将其split("...",schema_CGID,/ /)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM