-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolcheck
More file actions
executable file
·51 lines (46 loc) · 1.48 KB
/
colcheck
File metadata and controls
executable file
·51 lines (46 loc) · 1.48 KB
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
#!/usr/bin/awk -f
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2014 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: check consistency of columns
#
# input: rows of numbers and strings
# output: lines with format different than first line
#
NR == 1 {
nfld = NF
for (i = 1; i <= NF; i++)
type[i] = isnum($i)
printf("first line contains %d fields\n", nfld)
printf("%s", "fields are: ")
for (i = 1; i <= NF; i++)
printf("%s ", type[i] ? "NUM" : "STR")
print ""
print ""
}
{ if (NF != nfld) {
printf("%d: %s : %d fields\n",
NR, $0, NF)
}
for (i = 1; i <= (NF <= nfld ? NF : nfld); i++)
if (isnum($i) != type[i]) {
printf("%d: %s : field %d not a %s\n",
NR, $0, i, type[i] ? "number" : "string")
}
}
function isnum(n) {
return n ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eE][+-]?[0-9]*)?$/
}