-
Notifications
You must be signed in to change notification settings - Fork 0
/
longlines
executable file
·58 lines (49 loc) · 1.4 KB
/
longlines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
##############################################################################
#
# NAME: longlines
#
# DESCRIPTION: Show the lines that exceed a given number of characters.
# The output shows the file, line number and contents.
# If the output is redirected to a file, sch file can then be
# used with Vim's quickFix mode.
#
# USAGE: longlines [-l MAX_LENGTH] FILE [ FILE2 [FILE 3...]]
# -h Show usage
# -l MAX_LENGTH Maximum allowed line length
#
# DEPENDENCIES: None
#
##############################################################################
#
DEFAULT_LINE_LENGTH=80
#-----------------------------------------------------------------------------
usage()
{
sed -e 's/^ //' <<'USAGE'
Usage:
longlines [-l MAX_LENGTH] FILE [ FILE2 [FILE 3...]]
-h Show usage
-l MAX_LENGTH Maximum allowed line length
USAGE
exit $1
}
#-----------------------------------------------------------------------------
# Only asking for help
[[ $1 = '-h' ]] && usage 0
# How long the lines can be
if [[ $1 = '-l' ]]
then
linelen=$2
shift
shift
else
linelen=$DEFAULT_LINE_LENGTH
fi
# Still need at least a file to check
[[ $# = 0 ]] && usage 1
awk -v linelen=$linelen '
{
if (length() > linelen)
printf("%s:%d:%s\n", FILENAME, NR, $0);
}' "$@"