tofrodos 初步學習筆記

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章