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 shell 脚本中计算文件中的行数,但我需要 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