5.1.2.3. Combining redirections
The following example combines input and output redirection. The
file text.txt is first checked for
spelling mistakes, and the output is redirected to an error log
file:
spell < text.txt
> error.log
The following command lists all commands that you can issue to
examine another file when using less:
mike:~> less --help | grep -i examine
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
|
The -i option is used for
case-insensitive searches - remember that UNIX systems are very
case-sensitive.
If you want to save output of this command for future reference,
redirect the output to a file:
mike:~> less --help | grep -i examine > examine-files-in-less
mike:~> cat examine-files-in-less
:e [file] Examine a new file.
:n * Examine the (N-th) next file from the command line.
:p * Examine the (N-th) previous file from the command line.
:x * Examine the first (or N-th) file from the command line.
|
Output of one command can be piped into another command
virtually as many times as you want, just as long as these commands
would normally read input from standard input and write output to
the standard output. Sometimes they don't, but then there may be
special options that instruct these commands to behave according to
the standard definitions; so read the documentation (man and
Info pages) of the commands you
use if you should encounter errors.
Again, make sure you don't use names of existing files that you
still need. Redirecting output to existing files will replace the
content of those files.