Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bfs(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

bfs(1)                                                               bfs(1)

NAME
     bfs - big file scanner

SYNOPSIS
     bfs [-] file

DESCRIPTION
     bfs is similar to ed, except that you cannot use it to make changes to
     the file. bfs is read-only, but it can process much larger files than ed.

     The maximum file size is 1024 Kbytes. The maximum number of lines is
     32,000; the maximum number of characters per line is 512 (including
     the newline character).

     bfs is usually more efficient than ed, since the file is not copied to
     a buffer.

     bfs commands may be entered interactively or read from a file (see xf
     below).

     -    suppresses the usual displaying of

          -  the size of a file

          -  error messages

     file name of the file that you want to scan with bfs.

   Output

     bfs prints the size of the file being scanned as well as the size of
     any file written with the w command.

     As with ed, entering P <RETURN> causes an asterisk to be used as the
     input prompt. If errors occur in * mode, bfs issues an error message
     and exits. Entering P <RETURN> again deactivates the display of the *
     prompt and the error messages.

   Addresses

     All address formats described under ed are supported. The following
     additional options are available:

     -  Regular expressions can be enclosed in >...> and <...< in addition
        to /.../ and ?...?. In this context, > indicates a downward search
        to the end of the file, while < indicates an upward search to the
        beginning of the file. However, in contrast to / or ?, the search
        does not wrap around from the end of the file to the beginning or
        vice versa.

     -  Only the letters a to z may be used to mark lines. All 26 marks are
        remembered (stored).



Page 1                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

   Commands

     There are some commands that function as in ed and others that are
     only available with bfs. The two types are given below in separate
     alphabetical listings.

     ed-like commands

     The following commands function as in ed, with the exception of a few
     minor differences which are indicated at the appropriate place. A
     detailed description of these commands is provided under ed.

     e file
          You must always specify a file. bfs treats this file as the
          current file; only one file can be processed at a time.

     f    Prints the name of the file being scanned. There is no remembered
          file name.

     p    The commands 1,10 and 1,10p have the same meaning; the first 10
          lines are printed.

     P    Error messages are given in response to errors.

     q
     w    w is independent of output redirection, truncation, or crunching
          (see xo, xt, xc below).

     Additional bfs commands

     [range]xb/regularexpression/label

          range not specified:

          The search starts at the current line.

          If a string matching regularexpression is found in the specified
          range, the line containing the string becomes the current line,
          and a jump (either downward or upward) is made to label. Labels
          are set with the colon command :label (see below) and are located
          in the bfs command file (see xf).

          A jump is not possible in the following situations:

          -  either of the addresses in range is not between 1 and $ (the
             first and last lines of the file).

          -  the second address is less than the first.

          -  the regular expression does not match at least one line in the
             specified range (including the first and last lines).



Page 2                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

          xb is the only command which does not issue error messages in
          response to bad addresses. In such instances, it does nothing;
          and if it does nothing, you know that the specified address is
          invalid. It is therefore possible to use this command to test
          whether addresses are bad before other commands are executed.

          The command

          xb/^/label

          initiates an unconditional jump, i.e. no condition needs to be
          fulfilled.

          The xb command is allowed only if it is not read from a terminal.
          If it is read from a pipe, only a downward jump is possible.

     xbnlabel
     xbzlabel
          These two commands test the last saved return code of a UNIX sys-
          tem command (!command):

          -  xbz jumps to the specified label if the return code is 0
             (true).

          -  xbn jumps to the specified label if the return code is non-
             zero (false).

          Otherwise, xbn and xbz have no effect.

     xc[switch]
          Activates/deactivates crunching of output from the p or null com-
          mands. Crunched output has strings of tabs and blanks reduced to
          one blank; blank lines are suppressed.

          switch can have the values:

          0  Output is not crunched (default).

          1  Output is crunched.

          switch not specified:

          The setting of the switch is toggled.

     xffile
          bfs reads further commands from the named file. When the end-of-
          file character is reached, an interrupt signal is received or an
          error occurs, bfs reads the next command in the file containing
          the xf command.

          xf commands may be nested to a depth of 10.



Page 3                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

     xn   Lists the marks currently in use. Line marks are set by the k
          command (see ed).

     xo[file]
          Further output from the p and null commands is redirected to the
          named file. If the file does not exist, it is created and
          assigned the following permissions:

          rw-------

          Note: The permissions of a new file are controlled by umask.

          If the file already exists, it is truncated to a length of 0 and
          overwritten (if necessary); its permissions are not altered.
          Write-protected files are not overwritten.

          file not specified:

          Output is redirected to standard output. If you wish to redirect
          output to two different files in succession, you will have to
          redirect it to standard output between the two operations.

     xtn  Output from the p and null commands is truncated to at most n
          characters.

          xtn not specified:

          Output is restricted to 255 characters.

     xvdigit[ ][value]
          xv lets you assign a value to a variable. The variable name is
          specified by the digit following the xv command. digit can be any
          number between 0 and 9.

          The commands xv5100 and xv5 100 both assign the value 100 to the
          variable 5. The command xv61,100p assigns the value 1,100p to the
          variable 6.

          To reference a variable, put a % in front of the variable name.
          Thus using the assignments noted above for variables 5 and 6,
          each of the following commands:

          1,%5p
          1,%5
          %6

          will print the first 100 lines.







Page 4                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

          Entering the command:

          g/%5/p

          initiates a global search for the string 100 and prints each line
          containing these characters. The special meaning of the percent
          sign can be escaped by preceding it with a backslash, i.e. by
          entering \%.

          The command:

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

          matches and lists all strings that contain double quotes, fol-
          lowed by any number of characters, followed by a percent sign
          preceding the letter c, d or s. You can thus use this command to
          search for printf statements such as are used in awk or C.

          xv also makes it possible for you to store the first line of out-
          put from a UNIX system command into a variable. For this purpose,
          the first character of value must be an exclamation mark.

          The value of variable 6 could thus be incremented by one with the
          aid of the expr command:

          xv6!expr %6 + 1

          A somewhat more complicated example:

          .w tom
          xv5!cat tom
          !rm tom
          !echo "%5"

          The current line is written to the file tom from where it is then
          read with cat and stored in variable 5. The file tom is then
          deleted. The stored line is displayed by the echo command [see
          specialchar(5)].

          The special meaning of ! as the first character of value is
          escaped if it is preceded by a backslash. Thus,

          xv7\!date

          stores the value !date in variable 7.

          value not specified:

          The variable is assigned the number of the current line.





Page 5                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

     :label
          A label is a string that serves as a reference point for the xb,
          xbn, and xbz commands. You can write a label in a command file
          (see xf).

          label is terminated by a newline character. Blanks between the
          colon and the start of label are ignored. The : command may also
          be used to insert comments into a command file, since labels need
          not be referenced.

ERROR MESSAGES
     A question mark ? is output for errors in commands if bfs is not in *
     prompting mode (see the ed-like commands section, P command).

     Self-explanatory error messages are output if bfs is in * prompting
     mode.

EXAMPLES
   How labels work

     Create a file named animals with the five lines given below (line
     numbers are included in the file for the sake of clarity):

     1 Dogs
     2 Cats
     3 Mice
     4 Horses
     5 Cows

     You will also need to create a bfs command file named cmd1 so that
     commands can be read from it later. You first want to search for a
     line that has the word Mice in it. If Mice is not found, all lines are
     to be printed; if Mice is found, only the line containing Mice is to
     be printed. Then bfs is to terminate. Thus cmd1 must contain the fol-
     lowing:

     1,$xb/Mice/found
     1,$p
     xb/^/continue
     :found
     .p
     :continue
     q

     If Mice is not found, the instruction to print the current line must
     be skipped, since the last line would otherwise be printed twice (by
     the command 1,$p in line 2 and by the command .p in line 5). The
     xb/^/continue command therefore effects an unconditional jump to skip
     line 5.





Page 6                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

     After both files have been created, they are used as follows:

     $ bfs animals
     37
     xfcmd1
     3 Mice
     $

     If you want, you can now change Mice to Lice in either cmd1 or
     animals. All lines in animals will then be printed.

   How xbz and xbn work

     First a file is to be searched for five occurrences of the string
     Mice. This entails creating the bfs command file cmd2 with the follow-
     ing contents:

     xv55
     :1
     /Mice/
     xv5!expr %5 - 1
     ![ %5 != 0 ]
     xbz 1
     q

     The digit variable 5 is assigned a value of 5. The string Mice is then
     matched and printed once. Next the value in the digit variable 5 is
     decremented by 1. A check is then made to determine whether the value
     of 5 is still non-zero. If it is, a jump is made to label 1; if the
     value of 5 is 0, bfs is terminated.

     The file animals will again be used for the search:

     $ bfs animals
     37
     xfcmd2
     3 Mice
     3 Mice
     3 Mice
     3 Mice
     3 Mice
     $

     The string Mice is printed five times, since /.../ continues searching
     beyond the end of a file by starting once again at the beginning.









Page 7                       Reliant UNIX 5.44                Printed 11/98

bfs(1)                                                               bfs(1)

     If xbn is used, cmd2 must have the following contents in order to pro-
     duce the same results:

     xv55
     :1
     /Mice/
     xv5!expr %5 - 1
     ![ %5 = 0 ]
     xbn 1
     q

SEE ALSO
     ed(1).









































Page 8                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026