Os 5
Os 5
Pipe Commands
If you have a series of commands in which the output of one command is the input of the next,
you can pipe the output without saving it in temporary files:
first_command | next_command
For example, if you wanted to print out a sorted version of a file that contained a list of names
and phone numbers, you could use a pipe (as well as input redirection):
sort < my_phone_list | lpr
Similarly, in order to display the contents of the current directory, a screen-full at a time,you
can give the following commands:
$ ls > myfile
$ more myfile
Here, the listing of the directory is stored in the file, myfile, by the first command and this file
is then used as input by the more command.
The above two steps can be combined and executed as a single command without
creating a temporary file,
$ ls | more
The vertical bar (|) is the pipe character which indicates to the shell that the output of the
command before the ‘|’ is the input to the command after the ‘|’.
Filters Command
A filter is a program that takes its input from the standard input file, processes ( or filters)it and
sends its output to the standard output file. Linux has a rich set of filters that can be used to
work on data in an efficient way. Some examples of filters are:
• cat
• grep
• tr
• sort
• uniq
• sed
• awk
Some of the filters are discussed as follows:
The tr command
The tr command transliterates characters i.e. it copies the standard input to the standard
output with substitution or deletion of specific characters. The command has the following
syntax:
tr [options] [string1] < file1
The following is the list of options:
c Complements the set of characters in string1 with respect to the universe of characters whose
ASCII codes are 001 through 377 octal
d Deletes characters specified in string1
s Squeezes all repeated occurrences of a character to one character