Wednesday, April 26, 2006

Python note: SunOS file format switching

When I opened boost-jam src under SunOS, I found that each line was tailed with ^M. This is chr(13), which means that the end-of-line character for these files are \0xd\0xa.

To remove \0xd in the end-of-line character and switch files to format which SunOS reads, I wrote such a Python program.

import os
for sFile in os.listdir("."):
  os.system("sed 's/%s//g' %s>TEMP && mv TEMP %s"
  % (chr(13), sFile, sFile))

's/pattern/replace/g' is the general expression for string substitution with UNIX.

No comments: