Still the same problem as my last Python note, now I want to do it with vim.
This could be done by global pattern replacement. The command is:
:%s/pattern/replacement
The pattern needs to use literal mode: [Ctrl-v] key
In this case it's [Ctrl-v][CR], showed as ^M. The whole command will look like :%s/^M$//.
Sunday, April 30, 2006
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.
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.
Subscribe to:
Posts (Atom)