-2

这是我用作输入的数据

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
4

1 回答 1

3

你的问题在这里:

$OUTPUT = "DEM=" + $de + " ABC=" + $a + " DEF=" + $d + " GHI=" + $g + ", JKL=" + $j + ", MNO= " + m + ", PQR=" + p + ", STU=" + $s

您会自动输入所有名称并插入值。This:j = extract($TEXT, ".*STU\n\s*(\S+)\s+")显然返回 null 或空。JKL=仅当j不为空时才应添加。我建议检查该值是否不为空,然后将其添加到您的输出中。

于 2013-05-23T10:07:59.100 回答