2
0

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.

wcコマンドのmオプションって何に使ってるの?

Posted at

wc -m fileって使ったことある?

普通にwc -l .txtを叩こうとしたらタイプミスした時に以下のようにでて、mあったのかと思って調べて見た。

$ wc -p
wc: illegal option -- p
usage: wc [-clmw] [file ...]

-clwはなんとなく知ってたけどmあったのか。

#とりあえず適当にファイルを作成して使ってみることに

test.txt
aaaaaa
aaaaa
aaaaa
aaaaa
$ wc -m test.txt
      25 test.txt

調べて見たらPrint Char Countらしい。なんでm??
でもなんで25?aという文字は21文字しかない。

$ echo 'a' | wc -m
      2

??

$ echo '' | wc -m
      1

!!?

#結論
カウントは空文字でも1から始まって、それが各行に対して計算されるので、
7+6+6+6=25ということで25と出力されていたらしい。

#結論2
誰かこれ使ってる人いるの?

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?