Filter (Unix)

related topics
{math, number, function}
{system, computer, user}
{line, north, south}
{specie, animal, plant}

In UNIX and UNIX-like operating systems, a filter is a program that gets most of its data from its standard input (the main input stream) and writes its main results to its standard output (the main output stream). UNIX filters are often used as elements of pipelines. The pipe operator ("|") on a command line signifies that the main output of the command to the left is passed as main input to the command on the right.

The classic filter would be grep, which at it simplest prints to its output any lines containing a character string. Here's an example:

 cut -d : -f 1 /etc/passwd | grep foo

This finds all registered users that have "foo" as part of their username by using the cut command to take the first field (username) of each line of the UNIX system password file and passing them all as input to grep, which searches its input for lines containing the character string "foo" and prints them on its output.

Here is a perl equivalent to the above, which prints the whole line from the passwd file:

 perl -ne 'print if m/^[^:]*foo/' /etc/passwd

Or, to print only the username, without the rest of the line:

 perl -ane '$_ = shift @F; print "$_\n" if /foo/' -F: /etc/passwd

Common UNIX filter programs are: cat, cut, grep, head, sort, uniq and tail. Programs like awk and sed can be used to build quite complex filters because they are fully programmable.

List of UNIX filter programs

See also

Full article ▸

related documents
Dining cryptographers protocol
XPointer
Sequential access
Binary symmetric channel
Entropy encoding
Common Language Runtime
Name server
Small-C
Cfront
Yacc
Escape character
Typed link
XBasic
RIPEMD
SAX
Abbreviated Test Language for All Systems
Dia (software)
Common Language Infrastructure
ABC (programming language)
Poem code
Canonical Encoding Rules
Random access
A-law algorithm
Data element
Bit error ratio
Common Intermediate Language
Longitudinal redundancy check
Input
Grid network
Andrew Tridgell