--------------------------------------------------------------------------------- --------------------------------------------------------------------------------- http://textsnippets.com/posts/show/148 Never been to TextSnippets before? Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!) Remove ^M characters using vi (See related posts)http://textsnippets.com/posts/show/148#related ----------------------------------------------------------------- To remove all "^M" characters from a file, open it in vi and use this command: :%s/^M//g The "^M" in the above line has to be typed in by pressing CTRL+v and then CTRL+M. to vi (http://textsnippets.com/tag/vi) by Skybly (http://textsnippets.com/user/Skybly) on Sat Aug 27 21:28:27 +0000 2005 --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- Useful script for removing ^M characters from textfiles from: http://www.geocities.com/jasonpell/sources/undos.html --------------------- Cut here ------------------------ #!/bin/sh # Script written by Cristan Szmajda if [ $# -eq 0 ]; then echo "Usage: undos " fi for file do tr -d '\015' <$file >/tmp/.undos.$$ mv /tmp/.undos.$$ $file done --------------------- Cut here ------------------------ Usage Usage: undos This script is useful where there are no dos2unix tools available. --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- Using perl(1): # perl -i.bak -npe 's/\r\n/\n/g' file(s) where file(s) is one or more files to process. The modification is done in-place, with the original file stored with a .bak extension. Alternatively, you can use the tr(1) command: # tr -d '\r' < dos-text-file > unix-file dos-text is the file containing DOS text while unix-file will contain the converted output. This can be quite a bit faster than using perl. In FreeBSD, you can reformat DOS text files using the converters/dosunix port from the Ports Collection. Consult its documentation for details. --------------------------------------------------------------------------------- Sat Jan 10 04:11:00 UTC 2009 Ran across some more stuff on removing non-ascii non-printables. http://www.mail-archive.com/vim@vim.org/msg11271.html Excerpt from that page that works real good for me in vim: I'm not sure you've clearly defined non-ASCII characters (as it looks like the character you point out is ASCII 0x27, but I might be missing something), but if you mean things over 0x7f then you can do something like :%s/[^ -\x7f]//g to remove them. I don't know if you want to replace them with something smarter, as that may be more desired. Or, if you just want to find them, you can use /[\x80-\xff]