GNU coreutilsのcatで改行コードなどを確認する

最近知りました.

LC_MESSAGES=ja_JP.UTF-8のcat(1)
$ LC_MESSAGES=ja_JP.UTF-8 man cat | grep '\-A' -A25
       -A, --show-all           -vET と同じ

       -b, --number-nonblank
              空行以外に行番号を付ける。-n より優先される

       -e                       -vE と同じ

       -E, --show-ends
              行の最後に $ を付ける

       -n, --number
              全ての行に行番号を付ける

       -s, --squeeze-blank
              連続した空行の出力を行わない

       -t                       -vT と同じ

       -T, --show-tabs
              TAB 文字を ^I で表示

       -u     (無視)

       -v, --show-nonprinting
              ^ や M- 表記を使用する (LFD と TAB は除く)
LC_MESSAGES=Cのcat(1)
$ LC_MESSAGES=C man cat | grep '\-A' -A26
       -A, --show-all
              equivalent to -vET

       -b, --number-nonblank
              number nonempty output lines, overrides -n

       -e     equivalent to -vE

       -E, --show-ends
              display $ at end of each line

       -n, --number
              number all output lines

       -s, --squeeze-blank
              suppress repeated empty output lines

       -t     equivalent to -vT

       -T, --show-tabs
              display TAB characters as ^I

       -u     (ignored)

       -v, --show-nonprinting
              use ^ and M- notation, except for LFD and TAB
テストファイル作成
$ echo 'hoge
>       fuga
> ' | unix2dos > /tmp/test
odで中身確認
$ od -xc /tmp/test
0000000    6f68    6567    0a0d    6609    6775    0d61    0d0a    000a
          h   o   g   e  \r  \n  \t   f   u   g   a  \r  \n  \r  \n
0000017
普通にcat
$ cat /tmp/test
hoge
	fuga
-T でTABを ^I として表示
$ cat -T /tmp/test
hoge
^Ifuga
-v で\nやTABを除く制御コードを表示ここでは\rが^Mとして表示されている
$ cat -v /tmp/test
hoge^M
	fuga^M
^M
-t で -vT と同じ
$ cat -t /tmp/test
hoge^M
^Ifuga^M
^M
-E で行末に$を表示.\rがあると頭に付いてしまうよう
$ cat -E /tmp/test
$oge
$	fuga
$
Note
追記 2020-02-10)
Debianでreportbugしたらpatchが :)
Debian 11 BullseyeやUbuntu 21.04に入るかな?
https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=982208;filename=cat—​show-ends.diff;msg=10 🏛️
-A で -vET と同じ
$ cat -A /tmp/test
hoge^M$
^Ifuga^M$
^M$
-n で行番号を表示
$ cat -n /tmp/test
     1	hoge
     2		fuga
     3
-An で行番号と記号
$ cat -An /tmp/test
     1	hoge^M$
     2	^Ifuga^M$
     3	^M$

vimでは :set list, :set number でだいたい同じ感じでしょうか.

vim
  1 hoge$
  2 ^Ifuga$
  3 $

vim

環境
$ cat --version
cat (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund and Richard M. Stallman.
$ dpkg-query -W coreutils
coreutils	8.32-4+b1
$ lsb_release -dr
Description:	Debian GNU/Linux bullseye/sid
Release:	unstable
$ uname -m
x86_64

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.