Archive for the tag 'Input'

SBDavid

input and output redirection

input and output redirection

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 error.log

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 definition.

$ less –help | grep -i examine > examine-files-in-less

:$ 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.
+cmd Execute the less cmd each time a new file is examined.

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.

SBDavid

Input redirection

Input redirection

You may want a file to be the input for a command that normally wouldn’t accept a file as an option. This redirecting of input is done using the “<” (less-than symbol) operator.

Below is an example of sending a file to somebody, using input redirection.

#mail buddies@serverbuddies.com < /tmp/mail.txt

If the user buddies exists on the system, you don’t need to type the full address. If you want to reach somebody on the Internet, enter the fully qualified address as an argument to mail.

This reads a bit more difficult than the beginner’s cat file | mail someone, but it is of course a much more elegant way of using the available tools.