Extract a column from text file - Python -
i'm beginner py.
i need extract contents of column 12 huge flat text file every time word found within text file (similar awk '{print $12}' in bash) in python script.
so far have (example, not real code):
word = a_word a_word in data: column12 = data.split() print(column12[11]) i assumed should start counting 0 opposed 1, though may incorrect.
also, for loop correct type of code?
thanks!
loop on open file object:
with open('somefile') infile: line in infile: print(line.split()[11]) so, yes, use for loop , use 0-based indexing.
Comments
Post a Comment