#! /usr/bin/env python import sys, os def main(): """m2u.py [infiles]\n\nConvert mac-style line breaks ('\\r') to UNIX style ('\\n').""" # note the excessive error-checking! args = sys.argv[1:] if len(args) == 0 or args[0].lower() in 'h -h help -help'.split(): print main.__doc__ sys.exit(0) for arg in args: try: instr = open(arg).read() except IOError: print "Error reading file %s" % arg continue filename = os.path.split(arg)[1] tempname = '/tmp/' + filename try: outfile = open(tempname,'w') outfile.write(instr.replace('\r','\n')) except IOError: print "Error creating file %s" % tempname continue try: os.rename(tempname, arg) except IOError: print "Error moving %s to %s" % (tempname, arg) continue print 'Converted %s to UNIX format' % arg main()