diff options
Diffstat (limited to 'ipl/progs/getcol.icn')
-rw-r--r-- | ipl/progs/getcol.icn | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ipl/progs/getcol.icn b/ipl/progs/getcol.icn new file mode 100644 index 0000000..8524667 --- /dev/null +++ b/ipl/progs/getcol.icn @@ -0,0 +1,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 |