这里是我的shell脚本AWK阵列模式不匹配
#!/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"
我处理XLSX(Excel电子表格)与Python的工具xlxstocsv.py
文件。 我(想)这个字符串
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)
我处理我的文件就OK创建一个数组,但是,我想测试一下,如果我成功地找到字符串在此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
看起来像你的'schema_CGID [$ N]'值具有从我认为的输出领先的空间。用'print'试试没有与CGID [“CGID”] schema [“schema_CGID [$ N]”]“''相匹配的模式匹配? (还提供样本输入帮助**极大地**获得有用的帮助。) –
我不认为这是在bash中if else块的正确语法..从终端尝试此操作。例如:echo“foo bar bam”| if [[$(awk'{printf $ 3}')==“bam”]];然后回声“发现砰”;其他回声“巴姆不existecho”; fi 找到bam – zee