[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Output of entire files

These commands read and write entire files, possibly transforming them in some way.

3.1 cat: Concatenate and write files  Concatenate and write files.
3.2 tac: Concatenate and write files in reverse  Concatenate and write files in reverse.
3.3 nl: Number lines and write files  Number lines and write files.
3.4 od: Write files in octal or other formats  Write files in octal or other formats.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 cat: Concatenate and write files

cat copies each file (`-' means standard input), or standard input if none are given, to standard output. Synopsis:

 
cat [option] [file]...

The program accepts the following options. Also see 2. Common options.

`-A'
`--show-all'
Equivalent to `-vET'.

`-B'
`--binary'
On MS-DOS and MS-Windows only, read and write the files in binary mode. By default, cat on MS-DOS/MS-Windows uses binary mode only when standard output is redirected to a file or a pipe; this option overrides that. Binary file I/O is used so that the files retain their format (Unix text as opposed to DOS text and binary), because cat is frequently used as a file-copying program. Some options (see below) cause cat read and write files in text mode because then the original file contents aren't important (e.g., when lines are numbered by cat, or when line endings should be marked). This is so these options work as DOS/Windows users would expect; for example, DOS-style text files have their lines end with the CR-LF pair of characters which won't be processed as an empty line by `-b' unless the file is read in text mode.

`-b'
`--number-nonblank'
Number all nonblank output lines, starting with 1. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-e'
Equivalent to `-vE'.

`-E'
`--show-ends'
Display a `$' after the end of each line. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-n'
`--number'
Number all output lines, starting with 1. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-s'
`--squeeze-blank'
Replace multiple adjacent blank lines with a single blank line. On MS-DOS and MS-Windows, this option causes cat to read and write files in text mode.

`-t'
Equivalent to `-vT'.

`-T'
`--show-tabs'
Display TAB characters as `^I'.

`-u'
Ignored; for Unix compatibility.

`-v'
`--show-nonprinting'
Display control characters except for LFD and TAB using `^' notation and precede characters that have the high bit set with `M-'. On MS-DOS and MS-Windows, this option causes cat to read files and standard input in DOS binary mode, so the CR characters at the end of each line are also visible.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 tac: Concatenate and write files in reverse

tac copies each file (`-' means standard input), or standard input if none are given, to standard output, reversing the records (lines by default) in each separately. Synopsis:

 
tac [option]... [file]...

Records are separated by instances of a string (newline by default). By default, this separator string is attached to the end of the record that it follows in the file.

The program accepts the following options. Also see 2. Common options.

`-b'
`--before'
The separator is attached to the beginning of the record that it precedes in the file.

`-r'
`--regex'
Treat the separator string as a regular expression. Users of tac on MS-DOS/MS-Windows should note that, since tac reads files in binary mode, each line of a text file might end with a CR/LF pair instead of the Unix-style LF.

`-s separator'
`--separator=separator'
Use separator as the record separator, instead of newline.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 nl: Number lines and write files

nl writes each file (`-' means standard input), or standard input if none are given, to standard output, with line numbers added to some or all of the lines. Synopsis:

 
nl [option]... [file]...

nl decomposes its input into (logical) pages; by default, the line number is reset to 1 at the top of each logical page. nl treats all of the input files as a single document; it does not reset line numbers or logical pages between files.

A logical page consists of three sections: header, body, and footer. Any of the sections can be empty. Each can be numbered in a different style from the others.

The beginnings of the sections of logical pages are indicated in the input file by a line containing exactly one of these delimiter strings:

`\:\:\:'
start of header;
`\:\:'
start of body;
`\:'
start of footer.

The two characters from which these strings are made can be changed from `\' and `:' via options (see below), but the pattern and length of each string cannot be changed.

A section delimiter is replaced by an empty line on output. Any text that comes before the first section delimiter string in the input file is considered to be part of a body section, so nl treats a file that contains no section delimiters as a single body section.

The program accepts the following options. Also see 2. Common options.

`-b style'
`--body-numbering=style'
Select the numbering style for lines in the body section of each logical page. When a line is not numbered, the current line number is not incremented, but the line number separator character is still prepended to the line. The styles are:

`a'
number all lines,
`t'
number only nonempty lines (default for body),
`n'
do not number lines (default for header and footer),
`pregexp'
number only lines that contain a match for regexp.

`-d cd'
`--section-delimiter=cd'
Set the section delimiter characters to cd; default is `\:'. If only c is given, the second remains `:'. (Remember to protect `\' or other metacharacters from shell expansion with quotes or extra backslashes.)

`-f style'
`--footer-numbering=style'
Analogous to `--body-numbering'.

`-h style'
`--header-numbering=style'
Analogous to `--body-numbering'.

`-i number'
`--page-increment=number'
Increment line numbers by number (default 1).

`-l number'
`--join-blank-lines=number'
Consider number (default 1) consecutive empty lines to be one logical line for numbering, and only number the last one. Where fewer than number consecutive empty lines occur, do not number them. An empty line is one that contains no characters, not even spaces or tabs.

`-n format'
`--number-format=format'
Select the line numbering format (default is rn):

`ln'
left justified, no leading zeros;
`rn'
right justified, no leading zeros;
`rz'
right justified, leading zeros.

`-p'
`--no-renumber'
Do not reset the line number at the start of a logical page.

`-s string'
`--number-separator=string'
Separate the line number from the text line in the output with string (default is the TAB character).

`-v number'
`--starting-line-number=number'
Set the initial line number on each logical page to number (default 1).

`-w number'
`--number-width=number'
Use number characters for line numbers (default 6).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 od: Write files in octal or other formats

od writes an unambiguous representation of each file (`-' means standard input), or standard input if none are given. Synopsis:

 
od [option]... [file]...
od -C [file] [[+]offset [[+]label]]

Each line of output consists of the offset in the input, followed by groups of data from the file. By default, od prints the offset in octal, and each group of file data is two bytes of input printed as a single octal number.

The program accepts the following options. Also see 2. Common options.

`-A radix'
`--address-radix=radix'
Select the base in which file offsets are printed. radix can be one of the following:

`d'
decimal;
`o'
octal;
`x'
hexadecimal;
`n'
none (do not print offsets).

The default is octal.

`-j bytes'
`--skip-bytes=bytes'
Skip bytes input bytes before formatting and writing. If bytes begins with `0x' or `0X', it is interpreted in hexadecimal; otherwise, if it begins with `0', in octal; otherwise, in decimal. Appending `b' multiplies bytes by 512, `k' by 1024, and `m' by 1048576.

`-N bytes'
`--read-bytes=bytes'
Output at most bytes bytes of the input. Prefixes and suffixes on bytes are interpreted as for the `-j' option.

`-s [n]'
`--strings[=n]'
Instead of the normal output, output only string constants: at least n (3 by default) consecutive ASCII graphic characters, followed by a null (zero) byte.

`-t type'
`--format=type'
Select the format in which to output the file data. type is a string of one or more of the below type indicator characters. If you include more than one type indicator character in a single type string, or use this option more than once, od writes one copy of each output line using each of the data types that you specified, in the order that you specified.

Adding a trailing "z" to any type specification appends a display of the ASCII character representation of the printable characters to the output line generated by the type specification.

`a'
named character,
`c'
ASCII character or backslash escape,
`d'
signed decimal,
`f'
floating point,
`o'
octal,
`u'
unsigned decimal,
`x'
hexadecimal.

The type a outputs things like `sp' for space, `nl' for newline, and `nul' for a null (zero) byte. Type c outputs ` ', `\n', and \0, respectively.

Except for types `a' and `c', you can specify the number of bytes to use in interpreting each number in the given data type by following the type indicator character with a decimal integer. Alternately, you can specify the size of one of the C compiler's built-in data types by following the type indicator character with one of the following characters. For integers (`d', `o', `u', `x'):

`C'
char,
`S'
short,
`I'
int,
`L'
long.

For floating point (f):

F
float,
D
double,
L
long double.

`-v'
`--output-duplicates'
Output consecutive lines that are identical. By default, when two or more consecutive output lines would be identical, od outputs only the first line, and puts just an asterisk on the following line to indicate the elision.

`-w[n]'
`--width[=n]'
Dump n input bytes per output line. This must be a multiple of the least common multiple of the sizes associated with the specified output types. If n is omitted, the default is 32. If this option is not given at all, the default is 16.

The next several options map the old, pre-POSIX format specification options to the corresponding POSIX format specs. GNU od accepts any combination of old- and new-style options. Format specification options accumulate.

`-a'
Output as named characters. Equivalent to `-ta'.

`-b'
Output as octal bytes. Equivalent to `-toC'.

`-c'
Output as ASCII characters or backslash escapes. Equivalent to `-tc'.

`-d'
Output as unsigned decimal shorts. Equivalent to `-tu2'.

`-f'
Output as floats. Equivalent to `-tfF'.

`-h'
Output as hexadecimal shorts. Equivalent to `-tx2'.

`-i'
Output as decimal shorts. Equivalent to `-td2'.

`-l'
Output as decimal longs. Equivalent to `-td4'.

`-o'
Output as octal shorts. Equivalent to `-to2'.

`-x'
Output as hexadecimal shorts. Equivalent to `-tx2'.

`-C'
`--traditional'
Recognize the pre-POSIX non-option arguments that traditional od accepted. The following syntax:

 
od --traditional [file] [[+]offset[.][b] [[+]label[.][b]]]

can be used to specify at most one file and optional arguments specifying an offset and a pseudo-start address, label. By default, offset is interpreted as an octal number specifying how many input bytes to skip before formatting and writing. The optional trailing decimal point forces the interpretation of offset as a decimal number. If no decimal is specified and the offset begins with `0x' or `0X' it is interpreted as a hexadecimal number. If there is a trailing `b', the number of bytes skipped will be offset multiplied by 512. The label argument is interpreted just like offset, but it specifies an initial pseudo-address. The pseudo-addresses are displayed in parentheses following any normal address.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root l2-hrz on May, 9 2001 using texi2html