3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

不可視文字を手っ取り早く確認する方法

Posted at

やりたいこと

不可視文字の正体を暴く

コマンド

cat [ファイル名] | od -An -tx1c

オプションの説明

-An:標準では左側に基数が表示されるが、いらないので非表示にする。
-t:表示のタイプを指定。
x:16進数表示。uにすれば10進数表示。
1:1byteずつ表示する。
c:文字を表示する。

x1はなくても大丈夫といえば大丈夫ですが、半角スペースが分かりにくくなるので
あった方がいいです。

実験&少し説明

実験用ファイル作成

echo -e " a\n\rb\nc\nd\r\ne " | sed 's/ a/\ta/' >test
test
        a
b
c
d
e

コマンドを実行してみる

cat test | od -An -tx1c
  09  61  0a  0d  62  0a  63  0a  64  0d  0a  65  20  0a
  \t   a  \n  \r   b  \n   c  \n   d  \r  \n   e      \n

すなわち、
aの前にあるのは半角スペースではなくタブ文字(LF改行)
bは先頭文字かと思いきや、キャリッジリターンからのb(LF改行)
cは特になにもなし
dはCRLF改行(捉えようによってはデータがd[CR]でLF改行)
eは即改行かと思いきや、最後に半角スペースあり(LF改行)

odには他の使い方もあるかもしれませんが、私はこの用途でしか使用していません。

ファイルが複数行ある場合は16byte毎に改行されて表示されます。

以上

参考にさせて頂いたサイト様

http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230853/
https://hydrocul.github.io/wiki/commands/od.html

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?