man bool (Commandes) - print context matching a boolean expression

NAME

bool - print context matching a boolean expression

SYNOPSIS

bool [options] EXPRESSION [FILE...]

DESCRIPTION

Bool searches the named input FILEs (or standard input if the file name - is given) for the context of each pattern in the given EXPRESSION. If the input is HTML formatted, it is parsed and queried in a single pass.

By default, bool prints the first occurrence of each pattern in its context if the EXPRESSION is true. This consists of up to 60 characters preceding and following the pattern, until a beginning or end of paragraph is reached.

OPTIONS

-b, --byte-offset
Print the byte offset where the match occurred before each line of output.
-C NUM, --context=NUM
Print NUM characters (default 60) of output context for each pattern.
-c, --count
Suppress normal output; instead print a count of matching patterns for each input file.
-D NUM, --distance=NUM
Find patterns separated by NUM words (default 10) when using the NEAR operator.
-F, --fixed-string
Interpret EXPRESSION as a fixed string instead of a boolean expression.
-H, --with-filename
Print the filename for each match.
-h, --no-filename
Suppress the prefixing of filenames on output when multiple files are searched.
--help
Output a brief help message.
-i, --ignore-case
Ignore case distinctions in both the EXPRESSION and the input files.
-L, --files-without-match
Suppress normal output; instead print the name of each input file from which no output would normally have been printed.
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed.
-n, --line-number
Prefix each line of output with the line number within its input file.
-O NUM, --occurrences=NUM
Print NUM lines (default 1) of context for each pattern. No output is printed if the boolean expression is false. Every match is printed if NUM is set to 0, even if the expression is false.
-P, --with-pattern
Print the pattern for each match.
-p, --no-pattern
Suppress the prefixing of patterns on output.
-q, --quiet, --silent
Quiet; suppress normal output. Also see the -s or --no-messages option below.
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.
-V, --version
Print the version number of bool to standard error. This version number should be included in all bug reports (see below).

BOOLEAN EXPRESSION

A boolean expression is composed of operands separated by operators. The precedence of operators is evaluated from left to right.

Operands can be another boolean expression isolated between parentheses or a pattern. The latter is expressed as a sequence of characters delimited by spaces or enclosed in quotes. Some characters can be escaped using the backslash ('\'), other characters can be specified as SGML entities.

An operand must return a truth value. For a parenthesized expression, each operator within the expression is evaluated as described below. For a pattern, the operand is true if there are one or more occurrences of the sequence of characters in the input. Otherwise, the operand is false.

Operators are symbols denoting the logic to be performed. The AND operator returns true if the operands on both sides of the symbol are true, otherwise the expression is considered false. The OR operator returns true if either operand is true. The NOT operator returns true if the left operand is true and the right operand is false.

The NEAR operator, though not boolean, returns true if the operands on either side of the operator are within a specified number of words from each other. For example, the words "boolean" and "either" are separated by 6 words in the previous sentence. If the distance specified on the command-line is 10, the expression is true.

DIAGNOSTICS

Normally, exit status is 0 if matches were found, and 1 if no matches were found. Exit status is 2 if there were syntax errors in the expression or other system errors.

EXAMPLES

Output the first context where 'one' and 'two' are found, only if both are present:

# bool "one and two"

All occurrences of 'one' and 'two'. If the boolean expression is false, ie if only 'one' or 'two' is present, the return value is 1:

# bool -O0 "one and two"

Every byte offset where 'two' is separated from 'three' by no more than 5 words, but don't print any context:

# bool -O0 -C0 -D5 -b "two near three"

Only return the status of the boolean expression, 0 if matches were found and 1 otherwise:

# bool -q "one and (two near three)"

AUTHOR

Marc Tardif <intmktg@cam.org>

SEE ALSO