change_tabs.py 960 Bytes
from optparse import OptionParser

# Recibir input y output
parser = OptionParser()
parser.add_option("-i", dest="inF",help="Input vector file. Sentence is separated by tabs from values which are sparated by simple space", metavar="PATH")
parser.add_option("-o", dest="otF",help="output file name", metavar="PATH")

(options, args) = parser.parse_args()
if len(args) > 0:
    parser.error("Please indicate an input directory")
    sys.exit(1)

# Asignar variables
infile = options.inF
outfile = options.otF

# Abrir nuevo archivo
newfile = open(outfile, 'w')

# Reemplazar tab por espacio
with open(infile) as vectors:
	for line in vectors:
		# Aislar el numero de articulo de sus valores
		elements = line.rstrip().split('\t')

		# Ponemos una letra para facilitar la indentificacion posterior
		index = elements[0] + '_s'

		# Armar la nueva linea
		newline = ' '.join([index,elements[1]])
		newline = newline + '\n'
		newfile.write(newline)

newfile.close()