mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-06 07:49:02 +00:00
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.
28 lines
573 B
Bash
Executable File
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];
|
|
}
|
|
}
|
|
}' "$@"
|