Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
grep改行文字だけで構成される行を数えたいと思います。私は試した:
grep
grep -cx '\n' file.txt
しかし、これは私にはうまくいきませんでした。
の例file.txt:
file.txt
a bb c ddd wwfs
結果は 2 になるはずです。
空行を数えたい場合:
$ grep -c '^$' file 2
または、正規表現を必要としない場合:
$ fgrep -xc '' file 2
またはawk:
awk
$ awk '!NF{c++}END{print c}' file 2