Convert Between Unix and Windows Text Files
Convert Between Unix and Windows Text Files
- Knowledge Base
http://kb.iu.edu/data/acux.html
FTP
When using an FTP program to move a text file between Unix and Windows, be sure the file is transferred in ASCII format, so the document is transformed into a text format appropriate for the host. Some FTP programs, especially graphical applications (e.g., Hummingbird FTP), do this automatically. If you are using command line FTP, before you begin the transfer, enter:
ascii
Note: You need to use a client that supports secure FTP to transfer files to and from Indiana University's central systems. For more, see At IU, what SSH/SFTP clients are supported and where can I get them?
Note: These utilities are available only on Solaris systems. To determine which variety of Unix is running on your computer, see In Unix, how can I display information about the operating system?
tr
You can use tr to remove all carriage returns and Ctrl-z ( ^Z ) characters from a Windows file:
tr -d '\15\32' < winfile.txt > unixfile.txt
However, you cannot use tr to convert a document from Unix format to Windows.
awk
To use awk to convert a Windows file to Unix, enter:
awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt
Older versions of awk do not include the sub function. In such cases, use the same command, but replace awk with gawk or nawk.
1 di 2
15/06/2010 16.52
How do I convert between Unix and Windows text files? - Knowledge Base
http://kb.iu.edu/data/acux.html
Perl
To convert a Windows text file to a Unix text file using Perl, enter:
perl -p -e 's/\r$//' < winfile.txt > unixfile.txt
You must use single quotation marks in either command line. This prevents your shell from trying to evaluate anything inside.
vi
In vi, you can remove carriage return ( ^M ) characters with the following command:
:1,$s/^M//g
Note: To input the ^M character, press Ctrl-v , and then press Enter or return. In vim, use :set ff=unix to convert to Unix; use :set ff=dos to convert to Windows. This is document acux in domain all. Last modified on June 02, 2010. Copyright 2005-2010, The Trustees of Indiana University
2 di 2
15/06/2010 16.52