8.4.3 cat command (outputs files to the standard output)
Syntax
cat [-b] [-n] [-s] [-u] [path-name ...]
Description
This command outputs one or more files to the standard output. If there are multiple files, they are concatenated and output.
Arguments
- -b
Specifies that all non-blank output lines are to be assigned line numbers.
- -n
Specifies that all output lines are to be assigned line numbers beginning with 1. Each line number is displayed as six digits. If the number of lines is such that line numbers cannot be accommodated in six digits, the number of digits is increased as necessary. A tab is output after each line number. If you specify multiple path names, a line number is provided and docked to the path name of each specified file and the path name is output.
- -s
Specifies that multiple consecutive blank lines are to be compressed and output as a single blank line.
- -u
In UNIX, specifies that output buffering is to be suppressed.
In Windows, this option is ignored.
- path-name
Specify the path name of a file to be output. Multiple path names can be specified, in which case the specified files are concatenated and then output. If no path name is specified, or if - is specified as the path name, the input is read from the standard input.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 or greater |
Error termination |
Notes
A blank line is considered to be a line consisting of only a linefeed code [LF]. A line that includes [CR] + [LF] is not considered a blank line for the purposes of the -b and -s options. For this reason, files in Windows are normally not considered to include any blank lines.
In Windows, input and output are performed in the binary mode for files and for the standard input and standard output. No conversion of linefeed codes is performed.
If the standard output is a file and the specified path name indicates this file, the command outputs the following message and results in an error:
cat: file-name: input file is output file
Examples
These usage examples illustrate the results of executing the cat command on files abc.txt and abcdex.txt, whose contents are shown below. In the examples, represents a space and
represents a tab character.
abc.txt
aaaaaaaaaaa bbbbbbbb
cccccccccccccccc
dddddddddddd
-
abcdex.txt
aaaaaaaaaaa
bbbbbbbb cccccccccccc dddddddddddd eeeeeeeeeeeeeeeee
The files listed above are used as input files in the following examples, which illustrate the results of executing the cat command.
Specify the -b option to number non-blank output lines.
$ cat -b abc.txt 1
aaaaaaaaaaa 2
bbbbbbbb 3
4
cccccccccccccccc 5
6
7
dddddddddddd
Specify the -n option to number all output lines.
$ cat -n abc.txt 1
aaaaaaaaaaa 2
3
bbbbbbbb 4
5
6
cccccccccccccccc 7
8
9
10
11
dddddddddddd
Specify the -s option to squeeze consecutive blank lines and output them as a single blank line.
$ cat -s abcdex.txt aaaaaaaaaaa
bbbbbbbb cccccccccccc dddddddddddd eeeeeeeeeeeeeeeee
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\cat -w cat: illegal option -- w usage: cat [-bnsu] [file ...]
Display an error message because a file does not exist:
C:\TEMP>%ADSH_OSCMD_DIR%\cat file99 cat: file99: No such file or directory