[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 4


pg Command

Purpose

Formats files to the display.

Syntax

pg [ - Number ] [ -c ] [ -e ] [ -f ] [ -n ] [ -p String ] [ -s ] [ +LineNumber ] [ +/Pattern/ ] [ File ... ]

Description

The pg command reads a file name from the File parameter and writes the file to standard output one screen at a time. If you specify a - (dash) as the File parameter, or run the pg command without options, the pg command reads standard input. Each screen is followed by a prompt. If you press the Enter key, another page is displayed. Subcommands used with the pg command let you review or search in the file.

To determine workstation attributes, the pg command scans the file for the workstation type specified by the TERM environment variable. The default type is dumb.

When the pg command pauses and issues a prompt, you can issue a subcommand. Some of these subcommands change the display to a particular place in the file, some search for specific patterns in the text, and others change the environment in which the pg command works.

Changing Location Within the File

The following subcommands display a selected place in the file:

Page Displays the page specified by the Page parameter.
+Number Displays the page obtained by adding the Number value to the current page.
-Number Displays the page as specified by the Number value before the current page.
l (Lowercase L) Scrolls the display one line forward.
Numberl Displays at the top of the screen the line specified by the Number parameter.
+Numberl Scrolls the display forward for the specified number of lines.
-Numberl Scrolls the display backward for the specified number of lines.
d Scrolls half a screen forward. Pressing the Ctrl-D key sequence functions the same as the d subcommand.
-d Scrolls half a screen backward. Pressing the -Ctrl-D key sequence functions the same as the -d subcommand.
Ctrl-L Displays the current page again. A single . (dot) functions the same as the Ctrl-L key sequence subcommand.
$ Displays the last page in the file. Do not use this when the input is from a pipeline.

Searching for Text Patterns

The following subcommands search for text patterns in the text. (You can also use the patterns described in the ed command.) They must always end with a new-line character, even if the -n flag is used.

In an expression such as [k.a-z]k., the minus implies a range, as in a through z, according to the current collating sequence. A collating sequence defines equivalence classes for use in character ranges.

[Number]/Pattern/ Searches for the occurrence of the Pattern value as specified by the Number variable. The search begins immediately after the current page and continues to the end of the current file, without wraparound. The default for the Number variable is 1.
Number?Pattern?  

Number^Pattern^
  Searches backward for the occurrence of the Pattern value as specified by the Number variable. The searching begins immediately before the current page and continues to the beginning of the current file, without wraparound. The default for the Number variable is 1. The ^ notation is useful for Adds 100 terminals which will not properly handle the ? notation.

After searching, the pg command displays the line with the matching pattern at the top of the screen. You can change the position of the display by adding the m or b suffix to the search command. The m suffix displays the line with the matching pattern in the middle of the screen for all succeeding subcommands. The b suffix displays the line with the matching pattern at the bottom of the screen for all succeeding subcommands. The t suffix displays the line with the matching pattern at the top of the screen again.

Changing the pg Environment

You can change the pg command environment with the following subcommands:

[Number]n Begins examining the next file in the command line, as specified by the Number variable. The default for the Number variable is first.
[Number]p Begins examining the previous file on the command line, as specified by the Number variable. The default for the Number variable is first.
[Number]w Displays another window of text. If the Number variable is specified, sets the window size to the number of lines it specifies. This subcommand is the same as the [Number]z subcommand.
[Number]z Displays another window of text. If the Number variable is specified, sets the window size to the number of lines it specifies. This subcommand is the same as the [Number]w subcommand.
s File Saves the input in the specified file. Only the current file being examined is saved. This command must always end with a new-line character, even if you specify the -n flag.
h Displays an abbreviated summary of available subcommands.
q or Q Quits the pg command.
!Command Sends the specified command to the shell named in the SHELL environment variable. If this is not available, the default shell is used. This command must always end with a new-line character, even if the -n flag is used.

Attention:
  1. Some output is lost when you press the QUIT WITH DUMP (Ctrl-\) or INTERRUPT (Ctrl-C) key sequence because any characters waiting in the output queue are purged when the QUIT signal is received.
  2. If workstation tabs are not set every eight positions, unpredictable results can occur.

At any time output is being sent to the workstation, you can press the QUIT WITH DUMP or INTERRUPT key sequence. This causes the pg command to stop sending output and displays the prompt. Then you can enter one of the preceding subcommands at the command prompt.

If standard output is not a workstation, the pg command acts like the cat command, except that a header is displayed before each file.

While waiting for workstation input, the pg command stops running when you press the INTERRUPT key sequence. Between prompts these signals interrupt the current task and place you in the prompt mode.

Flags


-c Moves the cursor to the home position and clears the screen before each page. This flag is ignored if the clear_screen field is not defined for your workstation type in the terminfo file.
-e Does not pause at the end of each file.
-f Does not split lines. Normally, the pg command splits lines longer than the screen width.
-n Stops processing when a pg command letter is entered. Normally, commands must end with a new-line character.
-p String Uses the specified string as the prompt. If the String contains a %d value, that value is replaced by the current page number in the prompt. The default prompt is : (colon). If the specified string contains spaces, you must enclose the string in quotation marks.
-s Highlights all messages and prompts.
+LineNumber Starts at the specified line number.
-Number Specifies the number of lines in the window. On workstations that contain 24 lines, the default is 23.
+/Pattern/ Starts at the first line that contains the specified pattern.

Exit Status

This command returns the following exit values:

0 Successful completion.
>0 An error occurred.

Example

To look at the contents of a file one page at a time, enter:

pg filename

Files


/usr/bin/pg Contains the pg command.
/usr/share/lib/terminfo/* Contains the terminfo file that defines terminal types.
/tmp/pg* Contains the temporary file created when using pg command.

Related Information

The cat command, ed command, grep command.

File and Directory Access Modes in the AIX 5L Version 5.1 System Management Guide: Operating System and Devices.

Input and Output Redirection Overview and Shells Overview in the AIX 5L Version 5.1 System User's Guide: Operating System and Devices.

Files Overview in the AIX 5L Version 5.1 System User's Guide: Operating System and Devices.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]