0

早上好。我是 REGEX 的新手,所以我正在轻而易举地成功地克服它。

我需要从文件中删除一串字符,它遵循一个模式。在 RegExr 中,字符串工作正常,但是当我运行命令时,它会删除模式,但有时也会删除该行的其余部分。

我需要做的是从日志文件中删除“,T = 3054626560”。3054.....在整个文件中有所不同。

我的表达式看起来像这样 far-sed -i -r 's/(, T =).+?(([0-9]\w+))//g' logfile.log

输入数据示例-

    03/06/2020 10:28:59.885 (27044, T = 3054626560) [D] [INTERFACE] Response Str: {"Status":0}
    03/06/2020 10:29:04.490 (27044, T = 3054626560) [D] [INTERFACE] Parsed Cmd Str: {
       "ServerCmdRequest" : {
          "CmdId" : 529
       }
    }
    03/06/2020 10:29:04.492 (27044, T = 3054626560) [D] [INTERFACE] Response Str: {"ResponseData":{"NeedAuthList":[{"dataSourceName":"UA_SYSTEM_TABLES","index":0,"isSystemTableDB":true,"needAuthentication":false},{"dataSourceName":"ABC","index":1,"isSystemTableDB":false,"needAuthentication":false}]},"Status":0}
    03/06/2020 10:29:05.228 (27044, T = 3054626560) [D] [INTERFACE] Parsed Cmd Str: {
       "ServerCmdRequest" : {
          "CmdId" : 17,
          "CmdInputs" : {
             "isTestRun" : true
          },
          "IDList" : [ 63 ]
       }
    }
    03/06/2020 10:29:05.229 (27044, T = 3054626560) [D] [CELL ACC]  SCell Created: [0x7fe7b0046220]
    03/06/2020 10:29:05.231 (27044, T = 3054626560) [D] [CELL ACC]  SCell Destroyed: [0x7fe7b0046220]
    03/06/2020 10:29:05.232 (27044, T = 3054626560) [D] [INTERFACE] Response Str: {
       "Status" : 10121,
       "errorText" : "Process run results will be lost."
    }
4

1 回答 1

0

鉴于您的输入文件,我建议遵循以下程序。

cat test.txt | sed 's/, T = [0-9][0-9]*//g'

如果您想重写原始文件,您可以将其输出到临时文件,然后返回到您的日志文件。

样本输出:

    03/06/2020 10:28:59.885 (27044) [D] [INTERFACE] Response Str: {"Status":0}
03/06/2020 10:29:04.490 (27044) [D] [INTERFACE] Parsed Cmd Str: {
   "ServerCmdRequest" : {
      "CmdId" : 529
   }
}
03/06/2020 10:29:04.492 (27044) [D] [INTERFACE] Response Str: {"ResponseData":{"NeedAuthList":[{"dataSourceName":"UA_SYSTEM_TABLES","index":0,"isSystemTableDB":true,"needAuthentication":false},{"dataSourceName":"ABC","index":1,"isSystemTableDB":false,"needAuthentication":false}]},"Status":0}
03/06/2020 10:29:05.228 (27044) [D] [INTERFACE] Parsed Cmd Str: {
   "ServerCmdRequest" : {
      "CmdId" : 17,
      "CmdInputs" : {
         "isTestRun" : true
      },
      "IDList" : [ 63 ]
   }
}
03/06/2020 10:29:05.229 (27044) [D] [CELL ACC]  SCell Created: [0x7fe7b0046220]
03/06/2020 10:29:05.231 (27044) [D] [CELL ACC]  SCell Destroyed: [0x7fe7b0046220]
03/06/2020 10:29:05.232 (27044) [D] [INTERFACE] Response Str: {
   "Status" : 10121,
   "errorText" : "Process run results will be lost."
}
于 2020-03-07T15:26:30.967 回答