檔案內容的編碼 - Linux

By Lucy
at 2011-11-11T01:01
at 2011-11-11T01:01
Table of Contents
1.
file Sample5.java
./Sample5.java: ISO-8859-1 Java program text, with CRLF, NEL line
terminators
上面用file指令可以得到Sample5.java 檔案屬性,那我是想只要編碼訊息部分就好
還有個疑問是 file 指令找到編碼是指檔案名稱的編碼還是檔案內容編碼
因為我用 recode 工具轉碼 ISO-8859-1 轉 UTF-8 變成亂碼
但我用 BIG5 轉成 UTF-8 出來是OK, 所以我檔案內容編碼應該是BIG5 而ISO-8859-1是
檔案名稱編碼嗎?
2.
下面是我先用find 找出每個.java檔案路徑,
那我先判斷是每個檔案原本的編碼格式,之再做轉碼
那怎麼取得檔案屬性編碼字串進行比對選擇不同的處理
#!/bin/bash
find . -type f -iname '*.java' | while read path ; do
done
謝謝
--
※ 編輯: yshihyu 來自: 112.104.143.63 (11/11 02:07)
file Sample5.java
./Sample5.java: ISO-8859-1 Java program text, with CRLF, NEL line
terminators
上面用file指令可以得到Sample5.java 檔案屬性,那我是想只要編碼訊息部分就好
還有個疑問是 file 指令找到編碼是指檔案名稱的編碼還是檔案內容編碼
因為我用 recode 工具轉碼 ISO-8859-1 轉 UTF-8 變成亂碼
但我用 BIG5 轉成 UTF-8 出來是OK, 所以我檔案內容編碼應該是BIG5 而ISO-8859-1是
檔案名稱編碼嗎?
2.
下面是我先用find 找出每個.java檔案路徑,
那我先判斷是每個檔案原本的編碼格式,之再做轉碼
那怎麼取得檔案屬性編碼字串進行比對選擇不同的處理
#!/bin/bash
find . -type f -iname '*.java' | while read path ; do
done
謝謝
--
※ 編輯: yshihyu 來自: 112.104.143.63 (11/11 02:07)
推 ckclark:編碼是有模糊地帶的 要看你要轉的有哪幾種再來決定 11/11 02:15
→ yshihyu:我就是判斷檔案內容編碼是big5 or GB2312 就轉成UTF-8 11/11 02:19
推 ckclark:如果vim的fencs有設定好的話(每個檔案打開都正常) 11/11 02:21
→ yshihyu:我現在不是在vim 顯示上問題~就是我編譯器判讀是utf-8 11/11 02:22
→ yshihyu:程式碼都要utf-8.. 11/11 02:23
推 ckclark:因為vim可以用set fenc來轉檔案編碼 11/11 02:24
→ yshihyu:恩恩~但是我有很多檔案~ 這邊我都用vim 轉換就麻煩 11/11 02:24
推 ckclark:結果直接enca -x utf8 ...就搞定了 11/11 03:17
推 bitlife:在沒有更多資訊的情況下,BIG5會被認為是ISO-8859-1 11/11 06:19
→ bitlife:這是正常的,瀏覽器因為有OS國別/語系資訊,知道使用者用 11/11 06:20
→ bitlife:中文環境,所以可以先判斷檔案是否符合Big5?不符才判定為 11/11 06:21
→ bitlife:ISO-8859-1 11/11 06:21
→ bitlife:以前在DOS系統下,沒跑倚天中文系統時,Big5檔案type出來 11/11 06:22
→ bitlife:就像亂碼,而這些亂碼完全符合ISO-8859-1 11/11 06:22
推 ckclark:看起來是byte值0~255都符合iso-8859-1 11/11 19:29
Tags:
Linux
All Comments

By William
at 2011-11-15T02:36
at 2011-11-15T02:36

By Blanche
at 2011-11-17T23:00
at 2011-11-17T23:00

By Blanche
at 2011-11-18T03:40
at 2011-11-18T03:40

By Andy
at 2011-11-20T15:09
at 2011-11-20T15:09

By Anonymous
at 2011-11-21T15:48
at 2011-11-21T15:48

By David
at 2011-11-24T02:29
at 2011-11-24T02:29

By Skylar DavisLinda
at 2011-11-29T00:08
at 2011-11-29T00:08

By Anonymous
at 2011-11-30T22:21
at 2011-11-30T22:21

By Blanche
at 2011-12-04T09:28
at 2011-12-04T09:28

By Zanna
at 2011-12-09T00:40
at 2011-12-09T00:40

By Oscar
at 2011-12-13T11:56
at 2011-12-13T11:56

By John
at 2011-12-13T15:41
at 2011-12-13T15:41

By Hedwig
at 2011-12-17T06:22
at 2011-12-17T06:22
Related Posts
IPv6-to-IPv4轉換器

By Hedda
at 2011-11-10T21:44
at 2011-11-10T21:44
燒錄CentOS 5.7失敗

By Hazel
at 2011-11-10T17:45
at 2011-11-10T17:45
燒錄CentOS 5.7失敗

By Rebecca
at 2011-11-10T16:19
at 2011-11-10T16:19
ubuntu one with windows

By Una
at 2011-11-10T15:21
at 2011-11-10T15:21
nvidia顯卡驅動掛掉

By Noah
at 2011-11-10T13:46
at 2011-11-10T13:46