Re: Can someone do my job for me? :-)
If it's truly fixed length, with no record separator:
#!/usr/bin/python\n\nbadchar = '\\n'\nreclen = 100\n\ninf = open('/home/anderson/corrupt.txt', 'r')\noutf = open('/home/anderson/fixed.txt', 'w')\n\nwhile 1:\n rec = inf.read(reclen)\n if rec == '': break\n\n if rec[19] == badchar: rec = rec[:19] + ' ' + rec[20:]\n if rec[20] == badchar: rec = rec[:20] + ' ' + rec[21:]\n outf.write(rec)\n\ninf.close()\noutf.close()
Otherwise change the 100 to 101 on UNIX, 102 on Windows. Very rough, but it should get you there.
Edited by
admin
Feb. 28, 2005, 05:55:12 PM EST
Re: Can someone do my job for me? :-)
If it's truly fixed length, with no record separator:
#!/usr/bin/python
inf = open('/home/anderson/corrupt.txt', 'r')
outf = open('/home/anderson/fixed.txt', 'w')
while 1:
rec = inf.read(100)
if rec == '':
break
outf.write(rec[:19])
outf.write(' ')
outf.write(rec[21:])
inf.close()
outf.close()
Otherwise change the 100 to 101 on UNIX, 102 on Windows. Very rough, but it should get you there.
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."