Ditched '_find_SET()', since it was a no-value-added wrapper around
[python/dscho.git] / Mac / scripts / crlf.py
blob6506cdcec482ea08e8b91f167548345a63ab617c
1 #! /usr/local/bin/python
3 # Replace \r by \n -- useful after transferring files from the Mac...
4 # Run this on UNIX.
5 # Usage: crlf.py file ...
7 import sys
8 import os
9 import string
11 def main():
12 args = sys.argv[1:]
13 if not args:
14 print 'usage:', sys.argv[0], 'file ...'
15 sys.exit(2)
16 for file in args:
17 print file, '...'
18 data = open(file, 'r').read()
19 lines = string.splitfields(data, '\r')
20 newdata = string.joinfields(lines, '\n')
21 if newdata != data:
22 print 'rewriting...'
23 os.rename(file, file + '~')
24 open(file, 'w').write(newdata)
25 print 'done.'
26 else:
27 print 'no change.'
29 main()