Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!ames!aurora!labrea!decwrl!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: Using pipes within awk programs Summary: Described in AWK book. Keywords: awk, pipe Message-ID: <537@cresswell.quintus.UUCP> Date: 15 Jan 88 00:51:12 GMT References: <515@root44.co.uk> Organization: Quintus Computer Systems, Mountain View, CA Lines: 47 In article <515@root44.co.uk>, gwc@root.co.uk (Geoff Clare) ask about using pipes within awk programs. This feature is described in the book The AWK Programming Language Aho, Kernighan, & Weinberger Addison-Wesley ISBN 0-201-07981-X US$ 22 Page 62 (The getline function): Cmd | getline -- sets $0 and NF Cmd | getline Var -- sets Var The command is executed ONCE, just as a File in that position is opened ONCE. Page 59 (Closing Files and Pipes): close("...") closes a pipe or a file. BEWARE: files and pipes share a name space. That is, if AWK sees print Entry >>"cat" it will open a FILE called "cat" and from then on "cat" will designate that file. But if it sees print Remark | "cat" it will open a PIPE, and from then on "cat" will designate that pipe. close("cat") will close either a file or a pipe, depending on what the string was associated with. Avoid file names that look like commands. In SunOS 3.2, print | "cmd" works but "cmd" | getline doesn't. Anyone who is interested in mastering AWK should at least read this book. It describes the latest version, so there are some features (like user-defined functions, alas) which may not be available in the version you're using. The latest version is available for MS-DOS...