I want to do something like grep with python. I have a file, and I want to search it for a string, and print the line containing that string. Is this possible, and if so, how can I do it?
I want to do something like grep with python. I have a file, and I want to search it for a string, and print the line containing that string. Is this possible, and if so, how can I do it?
Another thanks!
So I'm doing
And getting backCode:for line in open("text.txt"): if "ref" in line: print line
(For example)Code:ref= 1
All I want displayed is the "1"
How do I format the output of print line to print just the second part (in bash it would be awk {print $2})
you just need to split .
i thought you have been reading the docs? split() is very basic for Python string processing.Code:print line.split("=")[-1]
Bookmarks