Convert between windows text file to Unix type
2013-06-13 00:00
489 查看
dos2unix and unix2dos
The utilities dos2unix and unix2dos are available for converting files from the Unix command line.To convert a Windows file to a Unix file, enter:
dos2unix winfile.txt unixfile.txt
To convert a Unix file to Windows, enter:
unix2dos unixfile.txt winfile.txt
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
To convert a Unix file to Windows, enter:
awk 'sub("$", "\r")' unixfile.txt > winfile.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.
Perl
To convert a Windows text file to a Unix text file using Perl, enter:perl -p -e 's/\r$//' < winfile.txt > unixfile.txt
To convert from a Unix text file to a Windows text file, enter:
perl -p -e 's/\n/\r\n/' < unixfile.txt > winfile.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.
相关文章推荐
- How to Convert Windows/DOS Text Files to Linux/UNIX Format
- How to Change the Icon for a File Type in Windows 7 and Vista(转)
- How to convert from windows timestamp to unix timestamp
- Clean RTF files to any encoding text file type
- Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
- error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
- A Tool to Convert Binary to Text File and Convert Back
- error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
- error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
- Cannot implicitly convert type 'System.Web.HttpPostedFile' to 'System.Web.HttpPostedFileBase'
- Cannot convert value of type 'SecTrustResultType' to expected argument type 'UInt32'
- 解决:Could not write to output file 'c:\windows\Microsoft.NET\Framework\........dll' -- '拒绝访问。 '
- Linux-Makefile(how to convert .out file to make .bin .elf, .hex file format)
- spring Failed to convert property value of type [$Proxy10] to required type
- 关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files… ‘Access is denied.’ 的解决办法
- 警告 - no rule to process file 'WRP_CollectionView/README.md' of type net.daringfireball.markdown for architecture i386
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- TextView cannot be resolved to a type
- Could not write to output file 'c:\WINDOWS\Microsoft.NET\Framework\..dll-拒绝访问
- Code: Writing Text to a File (Visual Basic)