admin管理员组文章数量:1516870
Sometimes, you will need to move files between windows and unix systems. Window files use the same format as Dos, where the end of line is signified by two characters, Carriage Return or
CR
or \r followed by Line Feed or
LF
or \n. Unix files, on the other hand, use only Line Feed (\n).
unix2dos
is a tool to convert line breaks in a text file from Unix format (Line feed) to DOS format (carriage return + Line feed) and vice versa.
- dos2unix command : converts a DOS text file to UNIX format.
- Unix2dos command : converts a Unix text file to DOS format
- Example
Task : Create a file in DOS or in notepad with following contents hello everybody welcome to unix unix is easy
- now copy this file in unix /home/geeks directory
$od –bc myfile.txt 0000000 150 145 154 154 157 040 145 166 145 162 171 142 157 144 171 015 h e l l o e v e r y b o d y \r 0000020 012 167 145 154 143 157 155 145 040 164 157 040 165 156 151 170 \n w e l c o m e t o u n i x 0000040 015 012 165 156 151 170 040 151 163 040 145 141 163 171 015 012 \r \n u n i x i s e a s y \r \n 0000060- The CR-LF combination is represented by the octal values 015-012 and the escape sequence \r\n.
- Note:
- The above output shows that this is a DOS format file. Now convert DOS file to UNIX format by using dos2unix command
$dos2unix myfile.txt $od –bc myfile.txt
- Conversion of this file to UNIX is just a simple matter of removing the \r. We can also convert UNIX file to DOS format by using unix2dos command
$unix2dos myfile.txt $od –bc myfile.txt
- After Conversion of this file to DOS, \r is added in DOS file.
版权声明:本文标题:跨平台不再难:学会使用Dos2Unix和Unix2Dos,轻松处理各种文档格式 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1771784968a3269437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论