I have a python script that will take each file in a directory, iterate through the contents of the file and create an output file for each input file. This output file may have duplicate entries and if it does I would like to take only the unique values similar to the UNIX command
uniq -u input.file > output.file
Although I could use shell scripts to do this I would like to include a line of python that will take only unique values. I know i can do this:
import os
os.system("uniq -u input.file > output.file")
However when I attempt to put this in a loop so that it will make unique all of the files I just made:
for curfile in fs:
if curfile[-3:]=='out':
os.system("uniq -u %s > %s") % (str(curfile), str(curfile[:-4] + ".uniq")
I get the following error:
unsupported operand type(s) for %: 'int' and 'tuple'
I have tried a few syntaxes to try to get the variables recognized but can’t find a similar enough example on the web. Any suggestions would be greatly appreciated.
You have
you need
First you format the string, then it goes to
os.system— as you have it now, the string goes toos.systemthen you attempt to%the result, which is anint. (The return code ofuniq.)