Ch 9 -Pipes, Filters, and Redirection

advertisement
Instructor: Prof. Michael P. Harris
Answers to Discussion Questions
Chapter 9
Pipes, Filters, and Redirection
Chapter 9
Pipes, Filters, and Redirection
ANSWERS TO DISCUSSION QUESTIONS (pp. 475-476)
1.
Explain redirection.
Redirection allows the user to redirect standard input and standard output. Standard input
is input coming from the keyboard. The user can request that a file be used as input
instead of the keyboard. Standard output is writing to the screen. The user can request
that output be sent to a place other than the screen, such as a file or the printer.
Redirection is very useful, especially in batch files or debugging problems.
2.
Explain the terms standard input, standard output, and standard error.
Standard input is the place the OS normally expects to find its input (keyboard).
Standard output is the place the OS normally expects to send its output (monitor). Both
standard input and standard output can be redirected. Standard error is the place from
which the OS writes error messages to the screen.
3.
Does every operating system command use standard input and standard
output? If not, why not?
Not all OS commands use standard input and standard output. For example, the COPY
command provides a service or "does a job". The only standard output is the message
that is written to the screen "1 file(s) copied". The DEL command does not even
write a message to the screen. Therefore, DEL does not use either standard input or
standard output.
4.
What is the difference between > and >> when redirecting output?
Both > and >> redirect the output of a command to some place other than the standard
output. The > will overwrite any file. The >> will append output to the end of any
existing file.
5.
Explain how the symbol < is used.
The < symbol asks the operating system to get its input from somewhere else other than
the keyboard. Look to whatever follows the symbol for output - usually a file.
6.
Keying in COPY DIR filename will not give you a file containing the
directory display. Why?
COPY is a command used to copy files not commands. DIR is a command and not a
file. Therefore COPY cannot be used to get a hard copy of the directory.
Carolyn Z. Gillay, Bette A. Peat, WUGXP Command Line
Franklin, Beedle & Associates, Inc. 2002 ©
Page 1
Instructor: Prof. Michael P. Harris
Answers to Discussion Questions
7.
Chapter 9
Pipes, Filters, and Redirection
What are filters?
Filters allow you to manipulate data. They read information from the keyboard, change
the input in a specific way, and then write the results to the screen. The operating system
filters are SORT, FIND, and MORE. All three filters allow you to control the way you see
data. SORT organizes the lines of a file (ascending or descending order). FIND shows
you only the lines you specify (character string). MORE shows you only a screenful at a
time.
8.
What do the three SORT parameters covered in this chapter—/n, /O, and /R
represent?
/R
/+n
/O
9.
Reverses sort order
Sorts based on column n
If not specified, data written to standard output. Specifying output file is faster
than redirecting standard output to same file.
Explain how the SORT command works. Describe any limitations of the
SORT command.
SORT expects information from standard input, the keyboard, reads the information, then
writes in alphabetical order to standard output (screen). Since SORT sorts on entire lines,
it is not very specific. You cannot extract the data by field. Thus, it cannot handle
simple sorts on date as a database program can.
10.
Identify one place that standard output can be written.
Standard output is always written to the screen. However, it can be redirected to a file or
a device (printer).
11.
What is the purpose of the FIND command?
FIND locates specific character strings in files or from standard output of commands and
writes the results to standard output.
12.
What are four parameters that are used with the FIND command and what
do they represent?
/V displays all lines not containing specified string.
/C displays only a count of lines containing the specified string.
/N displays line numbers on which the specified string appears.
/I does case-insensitive search for specified string.
13.
Why must the character string be enclosed in quotation marks when using
the FIND command?
The character string must be enclosed in quotation marks to limit the string of data FIND
is to locate. Without quotes, there would be no way for FIND to distinguish between the
character string and the file name.
Carolyn Z. Gillay, Bette A. Peat, WUGXP Command Line
Franklin, Beedle & Associates, Inc. 2002 ©
Page 2
Instructor: Prof. Michael P. Harris
Answers to Discussion Questions
14.
Chapter 9
Pipes, Filters, and Redirection
What are pipes (|)?
Pipes are used to allow standard output of one program to be used as standard input to the
next program. The use of pipes is not limited to two programs as you may pipe together
many programs. The standard output of the program is written to a temporary file and
the next command (usually a filter) reads the temporary file as standard input. The
temporary files that “hold” the data until the next command can process it are
automatically deleted when you are finished with your chain of commands.
15.
Are there any restrictions on the use of pipes? What are they?
Pipes can only be used with information generated from standard output. Thus, pipes
only work with commands that have standard output. You cannot use it with files
directly. However, if a command writes to the screen, you can "pipe" it elsewhere. An
example would be TYPE THIS.FIL ¦ MORE. TYPE is the command that output is
piped to MORE. On the other hand, you could not key in THIS.FIL ¦ MORE. There
is no command preceding THIS.FIL.
16.
How is the MORE command used?
The MORE command is used when the user wants to read a long text file that would not
fit onto the screen, one screenful at a time. MORE displays one screenful of information
at a time. The MORE command pauses when the screen is full and when any key is
pressed the MORE command displays the next screenful of information. When there is no
more data in the file, the MORE command finishes by returning to the system prompt.
This is useful when you want to read standard output on the screen, as the screen will not
scroll.
17.
What are two useful features that extended features provides for the MORE
command?
The extended features allow you to move through a file one line at a time. You may also
select how many lines you want displayed. You may also determine which line you are
on. You may also skip lines.
18.
How can combining filters be useful?
You may combine filters to extract data that you wish to see – you can be more specific
in what data you request.
Carolyn Z. Gillay, Bette A. Peat, WUGXP Command Line
Franklin, Beedle & Associates, Inc. 2002 ©
Page 3
Download
Study collections