Linux下查看txt文档
生活随笔
收集整理的這篇文章主要介紹了
Linux下查看txt文档
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當我們在使用Window操作系統的時候,可能使用最多的文本格式就是txt了,可是當我們將Window平臺下的txt文本文檔復制到Linux平臺下查看時,發現原來的中文所有變成了亂碼。
$ ./configure --prefix=/usr/local $ make $ make install
3. 命令學習
該工具安裝完畢后,肯定要先了解下這個命令的使用方法吧。這個沒什么可說的:
$iconv --help我們會看到以下的內容:
Usage: iconv [OPTION...] [FILE...] Convert encoding of given files from one encoding to another.Input/Output format specification:-f, --from-code=NAME encoding of original text-t, --to-code=NAME encoding for outputInformation:-l, --list list all known coded character setsOutput control:-c omit invalid characters from output-o, --output=FILE output file-s, --silent suppress warnings--verbose print progress information-?
iconv -f 原編碼 -t 目標編碼 要轉換的文件
4. 編碼轉換:
學會了編碼的轉化。我們就舉了樣例示范一下:
$iconv -f gbk -t utf8 test.txt命令運行完畢后,你發現原來test.txt中的中文正常顯示了。可是打開原來的文件,卻發現還是亂碼,這個Easy,我們將輸出的內容輸入到文件里就可以。
$iconv -f gbk -t utf8 test.txt < test此時我們打開這個test文件就會發現,原來的中文顯示正常了^-^
注意:
假設不出意外的話。上面的安裝步驟可沒有那么順利。在make的時候,會提示以下的錯誤:
n file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make: *** [all] Error 2這個這個軟件本身存在的一個Bug,通過Google,發現一個解決該問題的補丁,內容例如以下:
--- srclib/stdio.in.h.orig 2011-08-07 16:42:06.000000000 +0300 +++ srclib/stdio.in.h 2013-01-10 15:53:03.000000000 +0200 @@ -695,7 +695,9 @@/* It is very rare that the developer ever has full control of stdin,so any use of gets warrants an unconditional warning. Assume it isalways declared, since it is required by C89. */ -_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) + _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#endif#endifPS:內容中的"+"表示新增的內容。"-"表示刪除的內容!
那我們僅僅要進行例如以下操作就可以解決問題:
1. 切換到srclib文件夾下:
$cd srclib
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif
3. 保存退出。然后再進行make, make install便可順利安裝^-^
參考資料:http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/
沒錯, 引起這個結果的原因就是兩個平臺下,編輯器對默認的編碼格式是不一樣的:
在Window平臺下。Notepad的默認編碼是ASCII碼或者GBK,而在Linux平臺下默認的是UTF-8(中文環境的情況),編碼的不同導致了原來文檔中的中文變成了亂碼。
解決的方法:
使用iconv命令將文檔的編碼進行轉換就可以。
iconv默認情況下,是沒有被安裝的。以下簡介下iconv的安裝過程:
1. 下載:
http://www.gnu.org/software/libiconv/#TOCdownloading
2. 安裝:
下載完畢后,切換到下載文件夾先進行解壓:
然后進入解壓后的文件里
$cd libiconv-1.14_2查看當中的README文件,我們能夠看到安裝步驟:(當然,假設您熟悉源代碼的安裝,這步全然能夠省略^-^)$ ./configure --prefix=/usr/local $ make $ make install
3. 命令學習
該工具安裝完畢后,肯定要先了解下這個命令的使用方法吧。這個沒什么可說的:
$iconv --help我們會看到以下的內容:
Usage: iconv [OPTION...] [FILE...] Convert encoding of given files from one encoding to another.Input/Output format specification:-f, --from-code=NAME encoding of original text-t, --to-code=NAME encoding for outputInformation:-l, --list list all known coded character setsOutput control:-c omit invalid characters from output-o, --output=FILE output file-s, --silent suppress warnings--verbose print progress information-?
, --help Give this help list --usage Give a short usage message -V, --version Print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
說的非常明確,就是依照以下的格式進行轉換:iconv -f 原編碼 -t 目標編碼 要轉換的文件
4. 編碼轉換:
學會了編碼的轉化。我們就舉了樣例示范一下:
$iconv -f gbk -t utf8 test.txt命令運行完畢后,你發現原來test.txt中的中文正常顯示了。可是打開原來的文件,卻發現還是亂碼,這個Easy,我們將輸出的內容輸入到文件里就可以。
$iconv -f gbk -t utf8 test.txt < test此時我們打開這個test文件就會發現,原來的中文顯示正常了^-^
注意:
假設不出意外的話。上面的安裝步驟可沒有那么順利。在make的時候,會提示以下的錯誤:
n file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/freeman/Downloads/libiconv-1.14_2/srclib' make: *** [all] Error 2這個這個軟件本身存在的一個Bug,通過Google,發現一個解決該問題的補丁,內容例如以下:
--- srclib/stdio.in.h.orig 2011-08-07 16:42:06.000000000 +0300 +++ srclib/stdio.in.h 2013-01-10 15:53:03.000000000 +0200 @@ -695,7 +695,9 @@/* It is very rare that the developer ever has full control of stdin,so any use of gets warrants an unconditional warning. Assume it isalways declared, since it is required by C89. */ -_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16) + _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); +#endif#endifPS:內容中的"+"表示新增的內容。"-"表示刪除的內容!
那我們僅僅要進行例如以下操作就可以解決問題:
1. 切換到srclib文件夾下:
$cd srclib
2. 改動stdio.in.h文件:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); #endif
3. 保存退出。然后再進行make, make install便可順利安裝^-^
參考資料:http://forum.z27315.com/topic/15662-%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91libiconv%E6%97%B6%E7%9A%84gets-undeclared-here%E9%94%99%E8%AF%AF/
轉載于:https://www.cnblogs.com/liguangsunls/p/7122605.html
總結
以上是生活随笔為你收集整理的Linux下查看txt文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse类自动生成注释
- 下一篇: linux问题总结