A filter is a program that reads a single input stream, transforms it in
some way, and writes the result to a single output stream, as shown in
Figure 1, below. By default, the output stream (called standard output
or just stdout) is connected to the terminal window that the program is
running in, and the input stream (standard input, or just stdin) is
connected to the keyboard, though in practice filters are rarely used to
process data typed in manually at the keyboard.
(diagram from http://www.tuxradar.com/content/exploring-filters-and-pipes#null )
Filters with Pipes
Command lines which use a filter will include a pipes to connect it to the stdout of one process and the stdin of another process.
For example, the command line below takes the output of "who" and sorts it. The sorted output is then passed to the lp command for printing. In this example, sort is a filter.
who | sort | lp
Both filters and pipes demonstrate a basic UNIX principle: Expect the output of every program to become the input of another, yet unknown, program to combine simple tools to perform complex tasks.
References
(diagram from http://www.tuxradar.com/content/exploring-filters-and-pipes#null )
Filters with Pipes
Command lines which use a filter will include a pipes to connect it to the stdout of one process and the stdin of another process.
For example, the command line below takes the output of "who" and sorts it. The sorted output is then passed to the lp command for printing. In this example, sort is a filter.
who | sort | lp
Both filters and pipes demonstrate a basic UNIX principle: Expect the output of every program to become the input of another, yet unknown, program to combine simple tools to perform complex tasks.
References
0 comments:
Post a Comment