57 using SED to process line terminators in Windows and UNIX documents
Source: Internet
Author: User
The plain text Format of UNIX and dos/windows systems is different, and dos/windows-based text files have a CR (carriage return) and LF (line break) at the end of each line, and UNIX text has only one line break.
If you want to convert a UNIX text to Windows text, you can use the following SED command line
Sed-e ' s/$/\r/' myunix.txt > Mywin.txt
In the script, the ' $ ' rule expression will match the end of the line, and ' \ R ' tells SED to insert a carriage return before it. Insert a carriage return before line break, and immediately, each line ends with CR/LF.
Although many programs do not care about the dos/windows format of the cr/lf text file, but there are several programs but care, the most famous is bash, as long as a return, it will be a problem.
If you want to convert a Windows text to a UNIX file, you can use the following SED command line:
Sed–e ' s/.$//' mywin.txt > Myunix.txt
An override rule expression matches the last character of a line, and the character happens to be a carriage return. We replace it with a null character so that it is completely removed from the output.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.