Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. awk
    1. Description
    2. Author
    3. Requirements
    4. Documentation
    5. Examples
    6. Changelog
    7. License

awk

  1. Outdated egg!
  2. awk
    1. Description
    2. Author
    3. Requirements
    4. Documentation
    5. Examples
    6. Changelog
    7. License

Description

A looping construct for processing input in a way similar to the awk tool.

Author

Originally by Olin Shivers. This implementation has been taken from PLT Scheme's awk library and minimally modified by felix winkelmann to work with CHICKEN.

Requirements

None

Documentation

See the SCSH documentation for awk.

Examples

Count non-comment lines in Scheme file:

(use awk)

(print
  (awk (read-line) (line) ([nlines 0])
    ("^[ \t]*;" nlines)
    (else (add1 nlines))))

Strip blank lines:

(use awk)

(awk (read-line) (line) ()
  ("[^ \t]" (print line)) )

Compute maximal line length:

(use awk)

(print 
  (awk (read-line) (line) ([max-len 0])
    (#t (max max-len (string-length line))))

Sort /etc/passwd file:

(use awk)

(define (read-passwd . port)
  (let ([line (apply read-line port)])
    (if (eof-object? line)
	(values line #f)
	(values line (string-split-fields ":" line #:infix)))))

(for-each
 (lambda (entry) (print (cdr entry)))
 (sort
  (awk (read-passwd) (line fields) ([ans '()])
    (#t (cons (cons (car fields) line) ans)) ) 
  (lambda (x y) (string<? (car x) (car y)))))

Changelog

License

 PLT Software
 Copyright (c) 1995-2002 PLT
 PLT software is distributed under the GNU Lesser General Public
 License (LGPL).