tofrodos 初步学习笔记

来源:互联网 发布:2017网络热搜词 编辑:程序博客网 时间:2024/05/22 00:21

1 . UNIX 下与 DOS 下回车键定义的不同
--使用 man tofrodos 可以获得以下信息
DOS  text  files  traditionally  have  carriage return and line feed pairs as their newline characters
while Unix text files have the line feed as their newline character .(意思是,dos文本文档因袭传统, 把
carriage return 和line feed 的组合作为换行符;然而,unix 文本文件把line feed 作为换行符)

--通常把carrige return 和 line feed 分别写作 CR 和 LF ; 其中, CR 本用于将光标回退到当前行首;LF用于向下一行
  CR 字符形式'/r' LF字符形式'/n';ascii 码值分别为10进制的13 和 10

--使用cat命令并加以 -A 选项可以呈现所有不可打印字符 ,其中包括回车符(newline character(s))
  dos文件回车符显示为 ^M$
  unix文件回车符显示为  $

  unix文件回车符用两个字符表示 /r/n
  dos 文件回车符用一个字符表示 /n


2 . unix 与 dos 文本文档格式转换工具
--名称 todos fromdos 函数(ubuntu环境)
--安装方法   $sudo apt-get install tofrodos
--函数格式   todos [options] [file]
             fromdos [options] [file]
--函数选项
  -b  将源文件file备份位file.bak ;file使用新格式
  -u  无论函数名为todos 或者fromdos ,-u都认为原文件为unix格式文件并转换位dos格式
  -d  无论函数名为todos 还是fromdos , -d都认为源文件为dos格式文件并转换为unix格式
  -o  覆盖源文件并且不做备份,这是默认选择(override)

3 . 格式转换实例
--todos
unix系统下编辑test原文件,输入input an enter之后回车;重复该动作一次。

$cat -A test
owner@YZY:~/notes$ cat -A test
input an enter$
input an enter$
$
owner@YZY:~/notes$ todos test
owner@YZY:~/notes$ cat -A test
input an enter^M$
input an enter^M$
^M$
owner@YZY:~/notes$


--fromdos

4 . sed实现格式转换(简单替换而已)
--unix to dos
$sed -e 's/$//r/g' myunix.txt >mydos.txt

--dos to unix
$sed -e 's/.$//g' mydos.txt >myunix.txt


原创粉丝点击