这是我用作输入的数据
TEXT = "*** This is for test \"ABC_DEF/ghi_JKL\"U 1234 5678\nThis is also for test\n\nTEST\n\nDEMO TEST\n\nDEM ABC DEF GHI\nCASE-0 192.168.1.0 192.168.1.1 192.168.1.2\n\nJKL MNO PQR STU\n 111 222\nEND\n-TestCase(HIP)=MAXPAYNE3\n-GameType(RPG)=SERIOUS SAM3\n"
我到目前为止的代码如下:
if(match($NV_SPECIFIC_PROBLEM, "CP AP COMMUNICATION FAULT")) {
de= extract($TEXT, ".*DEF.*?\n\s*(\S+)\s+")
a = extract($TEXT, ".*DEF.*?\n\s*\S+\s+(\S+)\s+")
d = extract($TEXT, ".*DEF.*?\n\s*\S+\s+\S+\s+(\S+)\s+")
g = extract($TEXT, ".*DEF.*?\n\s*\S+\s+\S+\s+\S+\s+(\S+)\s*")
j = extract($TEXT, ".*STU\n\s*(\S+)\s+")
m = extract($TEXT, ".*STU\n\s*\S+\s+(\S+)\s+")
p = extract($TEXT, ".*STU\n\s*\S+\s+\S+\s+(\S+)\s+")
s = extract($TEXT, ".*STU\n\s*\S+\s+\S+\s+\S+\s+(\S+)\s*")
$OUTPUT = "DEM=" + $de + " ABC=" + $a + " DEF=" + $d + " GHI=" + $g + ", JKL=" + $j + ", MNO= " + m + ", PQR=" + p + ", STU=" + $s
update(@OUTPUT)
}
这段代码给出了这个输出:
DEM=CASE-0, ABC=192.168.1.0, DEF=192.168.1.1, GHI=192.168.1.2, JKL=, MNO=111, PQR=, STU=222
但我想要输出如下:
DEM=CASE-0, ABC=192.168.1.0, DEF=192.168.1.1, GHI=192.168.1.2, MNO=111, STU=222