Debian Codegraph @

awklib/eg/prog/labels.awk

raw
1 # labels.awk --- print mailing labels
2 #
3 # Arnold Robbins, [email protected], Public Domain
4 # June 1992
5 # December 2010, minor edits
6
7 # Each label is 5 lines of data that may have blank lines.
8 # The label sheets have 2 blank lines at the top and 2 at
9 # the bottom.
10
11 BEGIN { RS = "" ; MAXLINES = 100 }
12
13 function printpage( i, j)
14 {
15 if (Nlines <= 0)
16 return
17
18 printf "\n\n" # header
19
20 for (i = 1; i <= Nlines; i += 10) {
21 if (i == 21 || i == 61)
22 print ""
23 for (j = 0; j < 5; j++) {
24 if (i + j > MAXLINES)
25 break
26 printf " %-41s %s\n", line[i+j], line[i+j+5]
27 }
28 print ""
29 }
30
31 printf "\n\n" # footer
32
33 delete line
34 }
35
36 # main rule
37 {
38 if (Count >= 20) {
39 printpage()
40 Count = 0
41 Nlines = 0
42 }
43 n = split($0, a, "\n")
44 for (i = 1; i <= n; i++)
45 line[++Nlines] = a[i]
46 for (; i <= 5; i++)
47 line[++Nlines] = ""
48 Count++
49 }
50
51 END {
52 printpage()
53 }