Archive for the tag 'output'

Using cat command to number nonempty output lines

-b, –number-nonblank
number nonempty output lines

root@dell:/etc# cat -b inittab
1 # /etc/inittab: init(8) configuration.
2 # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

3 # The default runlevel.
4 id:2:initdefault:

-n, –number
number all output lines

root@dell:/etc# cat -n inittab
1 # /etc/inittab: init(8) configuration.
2 # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
3
4 # The default runlevel.
5 id:2:initdefault:

Separating standard output from standard error

Constructs like these are often used by programmers, so that output is displayed in one terminal window, and errors in another. Find out which pseudo terminal you are using issuing the tty command first:

#make all 2> /dev/pts/7

To find the tty type

root@dell:~# tty
/dev/pts/1
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.