问题
如果我有一个长文件包含许多不同长度的行,我如何计算每行长度的出现次数?
例:
file.txt
this is a sample file with several lines of varying length
运行count_line_lengths file.txt将给出:
Length Occurences 1 1 2 2 4 3 5 1 6 2 7 2
想法?
count.awk:
{ print length($0); }
… …
$ awk -f count.awk input.txt | sort | uniq -c 1 1 2 2 3 4 1 5 2 6 2 7