I. Text formatting differences with UltraEdit when you open a Unix text file, you are always prompted whether to convert the file to a DOS format. When you edit a profile in Windows and then upload it to a Linux host with FTP, you find that the runtime reads the configuration file in error. Since there is no experience, analysis of half a day. UltraEdit Save As 1.DOS Terminator-cr/lf 2.unix Terminator-lf 3.mac Terminator-CR Specific analysis, open a Dos and UNIX text file separately under Utrledit , and then select hexadecimal edit to see its encoded content (you can replace the format bat file in bulk). The carriage return under UNIX is represented by 0x0a, while the carriage return under DOS is 0x0d0a. After editing with Utraledit under Windows, you can find the Convert to UNIX format under the File menu and then upload the host. However, there are problems, because some FTP tools can choose to transfer in text or binary format, then you must choose binary, otherwise the transmission will be changed to DOS format. The format difference between a Unix text file and a Windows/dos text file is primarily a two-point: line break: Unix (/N) windows/ DOS (/r/n) ctrl: ^J ^m^jdec: 10 13+10hex: 0A 0d+0acode: lf cr+lf file Terminator: Unix windows/dosctrl: ^D ^zdec: 04 26hex: 04 The difference between 1AASCII mode and binary mode is the handling of carriage return line, binary mode does not do any processing of data, ASCII mode converts carriage return to native carriage return character, for example: Unix is \ n, Under Windows is \r\n,mac is \ r. ASCII mode will convert the file, not to say that the different systems on the carriage return line interpretation is different, but different systems have different line terminator. The UNIX system downlink terminator is a byte, which is the hexadecimal 0 A, while the Windows system is twoByte, which is the hexadecimal 0d0a, so when you download files to the Windows system in ASCII mode from the UNIX FTP server (either binary or text files), each detected byte is 0 A, it will automatically insert a 0D, so if your file is a binary file, For example, executable files, compressed packages and so on, it must not be used. If your file is a text file under UNIX, you use the ASCII mode is correct, if you misuse the binary mode, you see in Windows that the file is not wrapped, inside a black square. in general, we'd better use binary, so that we can ensure that there is no error. If there is a problem with text format conversion, that is, the conversion between the UNIX-formatted text and the DOS-formatted text, there are a lot of tools you can do, don't take the risk of FTP transmission, especially if you are not very clear about these things. In a function like printf, if you appear a \ n, it represents a logical meaning that it represents the type of carriage return on the local system, so it is only <lf> on UNIX, but if you are programming on DOS like TRUBOC it outputs < Cr><lf>.
UltraEdit each time you open a new file, you are prompted:
File may not be in DOS format,
Do you want to convert File to DOS format?
Advanced--Configuration--File processing, DOS/UNIX/MAC processing, Unix/mac file detection/conversion, cancels the previously selected
Detect file types and prompt for changes, choose Disable
DOS, Mac, and Unix file formats I believe many friends have encountered these three kinds of file format interchange problem, today again encountered this problem, suddenly want to ask the bottom of the root, so finishing this document. File format differences Let's see what the difference is between these three guys.
Long ago, people used an old-fashioned telex typewriter as an input device, which used two characters to start a new line. One character moves the slider back to the first place (called Carriage return), and the other character moves the paper up a line (called a newline). When the computer came out, memory was once very expensive. Some people assume that there is no need to use two characters to denote the end of a line. So the UNIX developers decided they could use a character to represent the end of the line.
The Apple developer has defined the use. The guys who developed MS-DOS (and Microsoft Windows) decided to follow the old-fashioned ones. Three end-of-line formats are as follows: Unix Dos Mac This means that if you're trying to move a file from one system to another, you'll have trouble with line breaks. There is a power to change demand.
On the Windows platform, there is a powerful ultraedit that supports any interchange of three file formats for DOS, MAC, and Unix. There are corresponding options under the "File", "Convert" tab, which is very silly and powerful.
Let's take a look at the Unix/linux platform how to do it?
Method One: powerful Dos2unix dos2unix filename
Method Two: Powerful script sed ' s/^m//' filename > tmp_filename where ^m is simultaneously ctrl+v+m pressed out, indicating carriage return. or tr-d "\ r" filename or cat filename | Perl-pe ' ~s/\r//g ' > Tmp_filename
Method Three: Powerful vim vim filename:set fileformat=unix:w or vim filename:%s/^m//g:w and VI, VIM has automatic recognition function, can be automatically converted with the following settings. However, because the Mac format is very special, Vim's automatic detection of MAC format may be wrong. Please refer to: http://vimcdoc.sourceforge.NET/doc/usr_23.html vim filename:set fileformats=unix,dos,mac Batch Conversion Sometimes we might want to batch this conversion.
There are powerful ultraedit under Windows, the method of global replace or the method of building engineering can be converted in batch, please refer to http://tech.ddvip.com/2007-10/119380983936863.html. There are a lot of related gadgets under the Windows platform, such as multiu2d, Google. In the Unix/linux platform we need to use script files or channels, in essence, the above methods of automation.
Here are a few simple examples, sourced from http://bbs.chinaunix.net/viewthread.PHP?tid=412957&extra=&page=1:
Script 1:ls-l | awk ' {print $8} ' > Filename.txt n=1 nn= ' wc-l filename.txt | awk ' {print $ ' while ["$N"-le "$NN"]; Do templine= ' sed-n ' $N "P" filename.txt "' if [-N ' $TempLine"]; Then tmpfilename= $TempLine dos2ux $tmpfilename > file mv file $tmpfilename fi n=$ (($N + 1)) done
Script 2:for XFile in $ (egrep-l ^m ' Find-name ' *.txt '; find-name "*.sql" ') do echo "Start processing file" $XFILE if [-s $XFILE] Then tmpfile= $XFILE. tmp mv $XFILE $TMPFILE tr-d "\ r" $XFILE RM $TMPFILE Else continue fi done Channel method: Find. -type f |xargs-i Dos2unix {} PostScript similar to the way in which Mac formats are converted to the other two formats, there are Dos2unix/mac2unix tools in a Unix-like environment. In the computer world, format conversion is ubiquitous, such as character formatting, compression format, network protocol format, audio and video format, and so on. So you should pay more attention to the relevant work.
DOS, Mac, and Unix file formats + UltraEdit use