summaryrefslogtreecommitdiff
path: root/ipl/progs/getcol.icn
blob: 85246670b341ffe9ac8463438c666c4a7a0cddba (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
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
############################################################################
#
#	File:     getcol.icn
#
#	Subject:  Program to extract column from data
#
#	Author:   Ralph E. Griswold
#
#	Date:     March 26, 2002
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#   This program extracts a column from multi-column data.
#
#   The supported options are:
#
#	-n i	column number, default 1
#	-c s	column-separation characters, default ' \t'
#
############################################################################
#
#  Links:  options
#
############################################################################

link options

procedure main(args)
   local i, chars, col, line, opts

   opts := options(args, "n+c:")

   i := \opts["n"] | 1
   if i < 1 then stop("*** invalid column specifications")

   chars := cset(\opts["c"]) | ' \t'
   if *chars = 0 then stop("*** invalid character-separation specification")

   while line := read() do {
      line ? {
         every 1 to i - 1 do {
            tab(upto(chars)) | stop("*** column missing")
            tab(many(chars))
            }
         write(tab(upto(chars) | 0))
         }
      }
            
end