* Bo Morris <[email protected]> [2014-10-02 11:41]: > Hello all, hope everyone is doing well. > > When I run the linux command "hamachi list" i get something along the lines > of the following output > > 087-888-279 Pandora 25.x.x.xxx alias: not > set > 096-779-867 AM1LaptopBD-PC 25.x.x.xxx alias: not set > 097-552-220 OWS-Desktop 1 25.0.0.0 alias: not set > 099-213-641 DESKTOP 25.0.0.0 alias: not set > > I am trying to write a python script that will run the above command and > only print out the IP's that begin with 25. How do I strip out all other > text except for the IP's that begin with "25?"
There are a few assumptions that need to be made, for starters. Is the format always the same (ie, is the IP address always in column 3 separated by whitespace)? Looking at the line with "OWS-Desktop 1", the answer is no. That complicates things a bit. If it was true, you could use the string split method to get column 3. Maybe the fields are separated by a tab? A regex may be possible, but you will have similar issues to using split. I'm also assuming it's possible for there to be IP addresses that do not start with 25. Are you looking to isolate those? It's not necessary to write out to a file first. You can get the output from commands and work on it directly. Another approach would be to change the command you are running. I've never heard of hamachi list before; does it have any commandline options to display only IP addresses? -- David Rock [email protected] _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
