7.3. Pipes

If you open a pipe in an awk program, you must close it before opening another one. The command on the right-hand side of the pipe symbol is enclosed in double quotes. Only one pipe can be open at a time.

Example 7.16.
(The Database)
% cat names
					john smith
					alice cheba
					george goldberg
					susan goldberg
					tony tram
					barbara nguyen
					elizabeth lone
					dan savage
					eliza goldberg
					john goldenrod

(The Command Line)
% nawk '{print $1, $2 | "sort –r +1 –2 +0 –1 "}' names
(The Output)
tony tram
					john smith
					dan savage
					barbara nguyen
					elizabeth lone
					john goldenrod
					susan goldberg
					george goldberg
					eliza goldberg
					alice cheba
				

EXPLANATION

Awk will pipe the output of the print statement as input to the UNIX sort command, which does a reversed sort using the second ...

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.