LoginSignup
0
0

More than 3 years have passed since last update.

文字コード関係

Posted at

EXCELでtext形式で保存したら、perlファイルの読み込みでエラーになったので、調べてみると文字コードがあっていないと、コントロールコードとして読み取られてしまう模様。
fileの種類を調べて確認し、nkfを使ってperlのデフォルト文字列(UTF-8 BOMなし)に変換して読みむことで解決

linux

ファイルの種類を調べる

file

$ file url*
urllist-utf.txt:  Little-endian UTF-16 Unicode text, with CRLF, CR line terminators
urllist-utf8.csv: UTF-8 Unicode (with BOM) text, with CRLF line terminators
urllist-w80.txt:  UTF-8 Unicode text, with CRLF line terminators
urllist.csv:      UTF-8 Unicode (with BOM) text, with CRLF line terminators
urllist.txt:      Little-endian UTF-16 Unicode text, with CRLF, CR line terminators
urllist.xlsx:     Microsoft Excel 2007+

文字コード変換

nkf

$ nkf -w80 urlist.csv

オプション 文字コード
-j ISO-2022-JP
-s Shift_JIS
-e EUC-JP
-w8 UTF-8 (BOMあり)
-w80 UTF-8 (BOMなし)
-w16 UTF-16 BE (BOMあり)
-w16B 同上
-w16L UTF-16 LE (BOMあり)

参照 : [Linux] 文字コードを変換する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0