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

Commands Reference, Volume 1

bfs Command

Purpose

Scans files.

Syntax

bfsFile

Description

The bfs command reads a file specified by the File parameter, but does not process the file. You can scan the file, but you cannot edit it.

The bfs command is basically a read-only version of the ed command with two exceptions: the bfs command can process much larger files and has additional subcommands.

Input files can be up to 32,767 lines long, with up to 255 characters per line. The bfs command is usually more efficient than the ed command for scanning a file because the file is not copied to a buffer. The bfs command is most useful in identifying sections of a large file that can be divided, using the csplit command, into more manageable pieces for editing.

If you enter the P subcommand, the bfs command prompts you with an * (asterisk). You can turn off prompting by entering a second P subcommand. The bfs command displays error messages when prompting is turned on.

The bfs command runs in both single- and multi-byte environments. The language environment is determined by the setting of the LANG environment variable (in the /etc/environment file) for the shell.

Forward and Backward Searches

The bfs command supports all of the address expressions described under the ed command. In addition, you can instruct the bfs command to search forward or backward through the file, with or without wraparound. If you specify a forward search with wraparound, the bfs command continues searching from the beginning of the file after it reaches the end of the file. If you specify a backward search with wraparound, the command continues searching backwards from the end of the file after it reaches the beginning. The symbols for specifying the four types of search are as follows:

/Pattern/ Searches forward with wraparound for the Pattern.
?Pattern? Searches backward with wraparound for the Pattern.
>Pattern> Searches forward without wraparound for the Pattern.
<Pattern< Searches backward without wraparound for the Pattern.

The pattern-matching routine of the bfs command differs somewhat from the one used by the ed command and includes additional features described in the regcmp subroutine. There is also a slight difference in mark names: only lowercase letters a through z may be used, and all 26 marks are remembered.

Flags

- Suppresses the display of file sizes. Normally, the bfs command displays the size, in bytes, of the file being scanned.

Subcommands

The e, g, v, k, n, p, q, w, =, !, and null subcommands operate as explained in the ed command. However, the bfs command does not support a space between the address and the subcommand. Subcommands such as --, +++-, +++=, -12, and +4p are accepted. 1,10p and 1,10 both display the first ten lines. The f subcommand displays only the name of the file being scanned; there are no remembered file names. The w subcommand is independent of output diversion, truncation, or compression (the xo, xt, and xc subcommands, respectively). Compressed Output mode suppresses blank lines and replaces multiple spaces and tabs with a single space.

The following additional subcommands are available:

xf File Reads the bfs subcommands from the specified file. When the bfs command reaches the end of file or receives an interrupt signal, or if an error occurs, the bfs command resumes scanning the file that contains the xf subcommand. These xf subcommands can be nested to a depth of 10.
xo [File] Sends further output from the p and null subcommands to the named file, which is created with read and write permission granted to all users. If you do not specify a File parameter, the bfs command writes to standard output. Each redirection to a file creates the specified file, deleting an existing file if necessary.
:Label Positions a label in a subcommand file. The label is ended with a newline character. Spaces between the : (colon) and the start of the label are ignored. This subcommand can be used to insert comments into a subcommand file, since labels need not be referenced.
[Address1[,Address2]] xb/Pattern/Label Sets the current line to the line containing the specified pattern, and jumps to the specified label in the current command file if the pattern is matched within the designated range of lines. The jump fails under any of the following conditions:
  • The value of either the Address1 or Address2 parameter is not between the first and last lines of the file.
  • The Address2 value is less than the Address1 value.
  • The pattern does not match at least one line in the specified range, including the first and last lines.

This subcommand is the only one that does not issue an error message on bad addresses, so it may be used to test whether addresses are bad before other subcommands are run. The subcommand:

xb/^/label

is an Unconditional Jump.

The xb subcommand is allowed only if it is read from some place other than a workstation. If it is read from a pipe, only a Downward Jump is possible.

xt [Number] Truncates output from the p subcommand and the null subcommands to the number of characters. The default value of the Number parameter is 192.
xv[Digit] [Value] Assigns the specified Value to the Digit parameter. The value of the Digit parameter can be 0 through 9. You can put one or more spaces between Digit and Value. For example:

xv5 100
xv6 1,100p

assigns the value 100 to the variable 5 and the value 1,100p to the variable 6.

To reference a variable, put a % (percent sign) in front of the variable name. Given the preceding assignments for variables 5 and 6, the following three subcommands:

1,%5p
1,%5
%6

each display the first 100 lines of a file.

To escape the special meaning of %, precede it with a \ (backslash). For example:

g/".*\%[cds]/p

matches and lists lines containing printf variables (%c, %d, or %s).

You can also use the xv subcommand to assign the first line of command output as the value of a variable. To do this, make the first character of the Value parameter an ! (exclamation point), followed by the command name. For example:

xv5 !cat junk

stores the first line of the junk file in the variable 5.

To escape the special meaning of ! as the first character of Value, precede it with a \ (backslash). For example:

xv7 \!date

stores the value !date in the variable 7.

xbz Label Tests the last saved exit value from a shell command and jumps to the specified label in the current command file if the value is 0.
xbn Label Tests the last saved exit value from a shell command and jumps to the specified label in the current command file if the value is not 0.
xc [Switch] Turns compressed output mode on or off. (Compressed output mode suppresses blank lines and replaces multiple spaces and tabs with a single space.)

If the Switch parameter has a value of 1, output from the p subcommand and the null subcommands is compressed. If the Switch parameter is 0, this output is not compressed. If you do not specify a value for the Switch parameter, the current value of the Switch parameter, initially set to 0, reverses.

Exit Status

The following exit values are returned:

0 Successful completion without any file or command errors
>0 An error occurred.

Files

/usr/bin/bfs Contains the bfs command.

Related Information

The csplit command, ed or red command.

The environment file.

The regcmp or regex subroutine.

File and Directory Access Modes in AIX 5L Version 5.2 System User's Guide: Operating System and Devices introduces file ownership and permissions to access files and directories.

Directory Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices.

Files Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices describes files, file types, and how to name files.

Input and Output Redirection Overview in AIX 5L Version 5.2 System User's Guide: Operating System and Devices describes how the operating system processes input and output.

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