Files
mercury/tools/find_long_lines
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

42 lines
949 B
Bash
Executable File

#!/bin/sh
# vim: ft=sh ts=4 sw=4 et
#
# This script, when invoked with a number (representing a line length)
# and a list of filenames, will look for lines longer than the given length
# in each of the listed files. When it finds such a line, it prints
#
# - the name of the file,
# - line number within that file, and
# - the length of that line.
#
case "$#" in
0)
echo "usage: find_long_lines limit_length filename1 ..."
exit 1
;;
*)
LIMIT_LEN="$1"
export LIMIT_LEN
shift
;;
esac
awk "
BEGIN {
limit_len = ${LIMIT_LEN};
CUR_FILENAME = \"\";
line_number = 0;
}
{
if (FILENAME != CUR_FILENAME) {
CUR_FILENAME = FILENAME;
line_number = 0;
}
++line_number;
len = length(\$0);
if (len > limit_len + 0) {
printf \"%s:%d: %d\n\", FILENAME, line_number, len;
}
}" "$@"