每当找到 PUT_LOG 标记时,我都试图从 PUT_LOG 标记中提取 (LOG_LEVEL_DEBUG, CAPTIVE_RECVD_SIGCHLD) 我只想提取其中的信息并将其放入另一个文件中。
请找到要从中提取信息的代码片段...
PUT_LOG(LOG_LEVEL_DEBUG, CAPTIVE_EXECUTE_CMD,1,STRING, cmd);
PUT_LOG(LOG_LEVEL_DEBUG, CAPTIVE_EXECUTE_CMD,1,STRING, cmd);
PUT_LOG(LOG_LEVEL_DEBUG_ERR, CAPTIVE_EXECUTE_CMD_FAILED,1, STRING, cmd);
enter code here
my out put should be like this
LOG_LEVEL_DEBUG
CAPTIVE_EXECUTE_CMD
LOG_LEVEL_DEBUG_ERR
CAPTIVE_EXECUTE_CMD_FAILED
我已经写了这样的代码..你能修改并给我确切的代码吗
#!/usr/bin/env python
inFile = open("data.c")
outFile = open("result.txt", "w")
buffer = []
keepCurrentSet = True
for line in inFile:
buffer.append(line)
if line.startswith("PUT_LOG"):
#---- starts a new data set
if keepCurrentSet:
outFile.write("".join(buffer))
#now reset our state
keepCurrentSet = False
buffer = []
elif line.startswith("LOG_LEVEL_DEBUG"):
keepCurrentSet = True
inFile.close()
outFile.close()