You are looking at historical revision 8778 of this page. It may differ significantly from its current revision.
awk
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 and minimally modified by felix winkelmann to work with Chicken.
Requirements
None
Download
Documentation
See http://www.scsh.net/docu/html/man-Z-H-9.html#%_sec_8.2the SCSH documentation for {{awk}}.
Examples
Count non-comment lines in Scheme file:
<example> <init>(use awk)</init> (print
(awk (read-line) (line) ([nlines 0]) ("^[ \t]*;" nlines) (else (add1 nlines)))
</example>
Strip blank lines:
<example> <init>(use awk)</init> (awk (read-line) (line) ()
("[^ \t]" (print line)) )
</example>
Compute maximal line length:
<example> <init>(use awk)</init> (print
(awk (read-line) (line) ([max-len 0]) (#t (max max-len (string-length line))))
</example>
Sort /etc/passwd file:
<example> <init>(use awk)</init> (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))))))
</example>
Changelog
- 1.1 Adapted to new setup scheme
- 1.0 Initial release
License
PLT Software Copyright (c) 1995-2002 PLT PLT software is distributed under the GNU Lesser General Public License (LGPL).