Search code examples
pythoncut

Python Cut Example


I'm looking for a way in python to achieve similar functionality to the unix cut utility. I know I can make a system call and process my data that way but I'd like to make it a bit more "pythonic" and do it with python libraries.

Example text

abcde:12345

I'd like to delimit on : and keep the second field:

cut -d':' -f2

to produce:

12345

thoughts?


Solution

  • You can do:

    string.split(":")[1]
    

    where string is your text