python: extract parts from line when using different delimiter

I am reading stdin line by line:

for line in sys.stdin:

Each line has following format:

: 1631373881:0;echo

I need to extract the first number (epoch time) and the command (last part after ';')

How can I extract these when the delimiter is not the same?

Submitted September 12th 2021 by Admin


input_str = ": 1631373881:0;echo".split(";")
command = input_str[-1]
number = input_str[0].split(":")[1].replace(" ","") 

Admin | 1 month ago

Relevant Questions