I have Linux/Unix syslog file and I want to separate the date and the time into variables. How can I achieve it in python?
Here’s the log format:
Feb 26 14:20:04 laptop kernel: [19.392640] ip_tables: (C) 2000-2006 Netfilter Core Team
I want to put Feb in a variable and the same goes to the day (26), time (14:20:04), etc.
In shell scripting, I can do it by cut -d " " -f 1-4 where " " is the delimiter and 1-4 is the field number.
Thanks!
If you’re just wanting to emulate
cut, you can split on space and take entries 1-4.(Did you want just the first 3 fields instead?)
You could also use regex, but I don’t think it’s necessary in this case.