Files
mercury/tools/line_len_stats
Zoltan Somogyi 32efc77039 Add tools to find too-long lines.
tools/line_len_stats:
    A new script that computes and prints a histogram of the line lengths
    in the input given to it.

tools/find_long_lines:
    A new script that, when given a line length and a list of filenames,
    prints out the location of the lines in those files that are longer
    than the given line length.
2023-05-15 11:37:13 +10:00

28 lines
573 B
Bash
Executable File

#!/bin/sh
# vim: ft=sh ts=4 sw=4 et
#
# Generate a histogram of the line lengths in the input, whether that input
# comes from stdin or from a list of filenames on the command line.
#
# Usage: line_len_stats [filename ...]
#
awk '
START {
maxlen = 0;
}
{
len = length($0);
count[len] += 1;
if (len > maxlen) {
maxlen = len;
}
}
END {
for (len = 1; len <= maxlen; len++) {
if (count[len] != 0) {
printf "len %4d: %d\n", len, count[len];
}
}
}' "$@"