# -*- coding:utf-8 -*-
# column_selector.py
import sys
import os
filename = ''
targetname = ''
if len(sys.argv) < 2:
print 'Usage: python column_selector.py temp.txt'
sys.exit()
for i in xrange(len(sys.argv)):
if (i >= 1):
filename = sys.argv[i]
targetname = filename + '.out'
if os.path.exists(filename):
pass
else:
print filename + ' file not find'
sys.exit()
try:
with open(filename,'r') as reader:
with open(targetname,'w') as writer:
for line in reader:
fragment = line.split(',')
print len(fragment[1]), fragment[1]
if len(fragment[1]) == 0:
continue
if fragment[1][-1] == '\n':
outline = fragment[1]
else:
outline = fragment[1] + '\n'
writer.write(outline)
except Exception, e:
raise
print targetname,'saved...'