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.
UNIXシェルスクリプトでファイルの行数を数えたいのですが、80文字以内の行数が必要で、80文字を超える場合は複数行として数えます。
wc -l が行数をカウントすることは知っていますが、この種のことを指定するオプションがないことも知っています。
foldを使用して 80 文字を超える行を分割し、出力をwcにパイプします。
$ fold file | wc -l
これはあなたが望むことをするかもしれません:
sed -r 's,(.{80}),\1\n,g' filename | wc -l
fold答えはUNIXの方法に最も適していますが:
fold
awk '{n += 1+int(length/80)} END {print n}' filename