Filters
standard input file, processes it, and sends .the
from the
fher is a program that takes input provides various filters,such as cat,grep, WC, tr, and
A
file. Linux
output tothe standard output
effectively withdata. Thenext section details the various filter
cut, t0 enable youto work
vaiable in Linux.
The grep Filter
specified pattern of characters and displays all the lines
The grep filter scarches a file for a searched for is referred to as a regular
pattern that is
chat contain the pattern. The specifying aregular expression.
pression. The grep filter cannot be used without
Syntax
(filename)
grep regular expression
in the grep command. If you do not specifya file name, the grep
The filename is optional are typing text, grep searches th
the standard input file. While you
filter expects input from specified expression. T
contains the
line for the regular expression and displays the line if it
and d keys.
stopthe execution of the grep filter, press the <Ctrl>
Example:
Sgrep job <Enter>
wori.
job
job
task
<Ctrl> d
In this example, the grep filter waits for input from the standard input file. The grep tiler
searches for the word job when you enter the words work, job,and task. When the grep
, Options of the grep Filter
command. The options
The grep filter offers options that enable you to alter the output of the
available with the grep filter are as follows:
-n:You can use this option with the grep filter todisplay each line matching the
specified pattern, along with the line number. The line number is printed at the
beginning of the line.
the
c:You can use this option to display only a count of the lines that match
specified pattern.
the specified
-v: Youcan use this option to display all the lines that do not match
pattern.
combine options while
You must specify the option before the regular expression. You can
the -nv option.
using the grep filter. For example, to combine the -n and -v options, you can use
The wc Filter
in a file. You can
The wc filter is used to count the number of lines, words, and characters
the
alsouse the wcfilter to count the nunmber of lines, words, and characters typed by using
standard input file.
Syntax
wc [-lwc) (filename/s J
Example
$wC sample <Enter>
2 7
29 sample
The file sample has 2 1ines,7 words, and 29 characters.
standard input file, processes it, and sends .the
from the
fher is a program that takes input provides various filters,such as cat,grep, WC, tr, and
A
file. Linux
output tothe standard output
effectively withdata. Thenext section details the various filter
cut, t0 enable youto work
vaiable in Linux.
The grep Filter
specified pattern of characters and displays all the lines
The grep filter scarches a file for a searched for is referred to as a regular
pattern that is
chat contain the pattern. The specifying aregular expression.
pression. The grep filter cannot be used without
Syntax
(filename)
grep regular expression
in the grep command. If you do not specifya file name, the grep
The filename is optional are typing text, grep searches th
the standard input file. While you
filter expects input from specified expression. T
contains the
line for the regular expression and displays the line if it
and d keys.
stopthe execution of the grep filter, press the <Ctrl>
Example:
Sgrep job <Enter>
wori.
job
job
task
<Ctrl> d
In this example, the grep filter waits for input from the standard input file. The grep tiler
searches for the word job when you enter the words work, job,and task. When the grep
, Options of the grep Filter
command. The options
The grep filter offers options that enable you to alter the output of the
available with the grep filter are as follows:
-n:You can use this option with the grep filter todisplay each line matching the
specified pattern, along with the line number. The line number is printed at the
beginning of the line.
the
c:You can use this option to display only a count of the lines that match
specified pattern.
the specified
-v: Youcan use this option to display all the lines that do not match
pattern.
combine options while
You must specify the option before the regular expression. You can
the -nv option.
using the grep filter. For example, to combine the -n and -v options, you can use
The wc Filter
in a file. You can
The wc filter is used to count the number of lines, words, and characters
the
alsouse the wcfilter to count the nunmber of lines, words, and characters typed by using
standard input file.
Syntax
wc [-lwc) (filename/s J
Example
$wC sample <Enter>
2 7
29 sample
The file sample has 2 1ines,7 words, and 29 characters.