blob: e446ce9669643717ed326c25fd6177a78ef1463a (
plain)
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
|
#!/usr/bin/awk
#
# See ../README.md
#
#
# Run as: awk -f ch-1.awk < input-file
#
#
# Get rid of leading sign
#
/^[-+]/ {$0 = substr ($0, 2)}
#
# Validation
#
/[^0-9]/ {print "not an integer"; next}
/^(..)*$/ {print "even number of digits"; next}
length ($0) < 3 {print "too short"; next}
#
# Print the middle three digits
#
{print substr ($0, 1 + (length ($0) - 3) / 2, 3)}
|