0

Hello,

I want do somthing in python equal this code in bash

For example the file.txt in it "dani_web_the_best" and want print "web"

cat file.txt | cut -d"_" -f2

What equal cut -d"_" -f2 in python ?

5
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by zoro007
1

I dont know if its just me, but that dosent quite make that much sense. Just spend a little more time outlining exactly what you actually want, what your problem is. What you have already tried.

Then we will be much better at helping :)

0

I dont know if its just me, but that dosent quite make that much sense.

It's not just you.

0

I think my example its plain

I want code equal cut -d"_" -f2 in python.

Will understand me someone linux system admin

Waiting some one for help

0

I think 'cut -d"_"' means split on the "_" which would be .split("_") in python but you will have to explain what the rest is. So first you want to post your code that opens the file and reads it one record at a time, and you should be able to split each rec as well after a quick trip to the docs. We can help you from there if we know what you want to do.

1

Try not to confuse people. Those who knows python does not necessarily know bash. The same way you know bash but do not know python.
BTW, here is your code:

s="dani_web_needs_better_OP"
print s.split("_")[1]

One more advice, try to read a book. These things are covered in the introductory chapters.

Votes + Comments
yes
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.