Skip to content
Advertisement

python: print a single column using field separator

I am beginner with python. From a log, I want with a python to extract only the hostname that are located in the middle of each line line ( between “command_wrappers INFO:” and “: pg_receivewal: switched to timeline”) in order to lauch a command to each of thoses servers.

Here are the lines of the log:

JavaScript

Here is the result that I am looking for:

JavaScript

Is there a simple way to get such result ?

Advertisement

Answer

In general you will usually use a Regex to solve this kind of stuff, but in your case. You can simply use split() method.

If your case it would look like:

JavaScript

If the logs looks exactly as the example…

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement