關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • Unix 及 Windows 文字檔轉換

    Posted on February 13th, 2006 Sam Tang 1 comment

    大家如果試過在 Linux 及 Windows 文字檔分享的話,會發現文字檔的 “換行” 不一樣。在 Windows 用記事本開啟 Unix 文字檔時,文件不會開新行,需要使用支援 Unix 格式的文字編輯器才可看到分行;而在 Linux 開啟 Windows 的文字檔時,在每一行最後會有字元 Ctrl-m (^M)。以下是使用 Perl 在 Linux 下將文字檔轉換的方法:

    Windows 格式 -> Unix 格式
    perl -p -e ‘s/\r$//’ < winfile.txt > unixfile.txt

    Unix 格式 -> Windows 格式
    perl -p -e ‘s/\n/\r\n/’ < unixfile.txt > winfile.txt


     

    One response to “Unix 及 Windows 文字檔轉換”

    1. UNIX WINDOWS MAC三者的回车都不一样,好像是:windows是0x0d 0x0a
      UNIX是0x0d MAC是0x0a吧。记不太清楚了。大体上是这样的。

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word