You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone, I have the following data (in the code) and I would like to extract the closest timestamp to the data, such as "Tue Nov 12 02:30:51 2000". However, the result I obtained is not what I wanted. What should I do, thank you.
`['Tue Nov 12 01:30:51 2000', 'cmd_prefix a\n cmd output1\n']
DATA: ['cmd_prefix a\n cmd output1\n']
TIMESTAMP: ['Tue Nov 12 01:30:51 2000']`
data = """
[Tue Nov 12 01:30:51 2000]
abcd
[Tue Nov 12 02:30:51 2000]
1234
cmd_prefix a
cmd output1
cmd_prefix b
[Tue Nov 12 03:30:51 2000]
abcd
[Tue Nov 12 04:30:51 2000]
1234
cmd_prefix a
cmd output2
cmd_prefix b
"""
timestamp = (
LineStart()
+ Suppress(Optional(Literal("[")))
+ Regex(r"\w{3} \w{3}\s+\d{1,2} \d{2}:\d{2}:\d{2} \d{4}")
+ Suppress(Optional(Literal("]")))
)
cmd_prefix_cmd = LineStart() + Literal("cmd_prefix")
cmd_prefix_m_cmd = Combine(cmd_prefix_cmd + Literal(" a"))
cmd_prefix_z_cmd = Combine(cmd_prefix_cmd + Literal(" b"))
cmd_prefix_parse = Suppress(SkipTo(cmd_prefix_m_cmd)) + SkipTo(cmd_prefix_z_cmd)
timestamp_with_data = Group(
OneOrMore(timestamp)("TIMESTAMP")
+ FollowedBy(cmd_prefix_parse)
+ cmd_prefix_parse("DATA")
)
parser = OneOrMore(timestamp_with_data)
results = parser.parseString(data)
for result in results:
print(result.dump())
The text was updated successfully, but these errors were encountered:
Hello everyone, I have the following data (in the code) and I would like to extract the closest timestamp to the data, such as "Tue Nov 12 02:30:51 2000". However, the result I obtained is not what I wanted. What should I do, thank you.
`['Tue Nov 12 01:30:51 2000', 'cmd_prefix a\n cmd output1\n']
The text was updated successfully, but these errors were encountered: