public final class Grep extends Object
NAME
grep - print lines matching a pattern
SYNOPSIS
grep <args> | |
grep <regexp> | |
grep <regexp> <files> | |
grep <regexp> <inputs> | |
grep <pattern> | |
grep <pattern> <files> | |
grep <pattern> <paths> | |
grep <pattern> <inputs> | |
grep [-ivFnclx] <regexp> | |
grep [-ivFnclx] <pattern> | |
grep [-ivFnclx] <regexp> <files> | |
grep [-ivFnclx] <regexp> <paths> | |
grep [-ivFnclx] <regexp> <inputs> | |
grep [-ivFnclx] <pattern> <files> | |
grep [-ivFnclx] <pattern> <paths> | |
grep [-ivFnclx] <pattern> <inputs> |
See Grep.Interface
for the corresponding command signature methods.
DESCRIPTION
The grep utility searches the input, selecting lines matching a pattern; the types of patterns are controlled by the options specified.
By default, an input line is selected if any pattern, treated as an entire regular expression matches any part of the line excluding the terminating newline character(s). By default, each selected input line is written to the output.
Regular expression matching is based on text lines. Since newline character(s) separate or terminate patterns, regular expressions cannot contain newline character(s). Similarly, since patterns are matched against individual lines (excluding the terminating newline character(s)) of the input, there is no way for a pattern to match newline character(s) found in the input.
Regular expressions used in this command must be based on the Java regular expression syntax
.
Options
The following options are supported:
-i | --ignoreCase | Match lines ignoring the case when comparing the strings, also known from Unix with its acronym 'i'. | |||
-v | --invertMatch | Invert the match result, that is, a non-matching line is written to the output and a matching line is not. This option is also known from Unix with its acronym 'v'. | |||
-F | --fixedStrings | Use fixed-strings matching instead of regular expressions. This is
usually faster than the standard regexp version.
(This option is ignored if a | |||
-n | --lineNumber | Prefix each line of output with the line number within its input file. | |||
-c | --count | Suppress normal output; instead print a count of matching lines for
each input file. With the -v , --invertMatch option,
count non-matching lines. | |||
-l | --matchingFiles | Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. | |||
-x | --wholeLine | Select only those matches that exactly match the whole line
excluding the terminating line ending.
(This option is ignored if a |
OPERANDS
The following operands are supported:
<regexp> | : | String | Lines will be printed which match the given regular expression. The
regexp string is surrounded with ".*" on both sides unless
the --wholeLine option is specified. If the
--fixedStrings option is used, plain string comparison is
used instead of regular expression matching. | ||
<pattern> | : | java.util.regex.Pattern | Lines will be printed which match the given pattern. | ||
<paths> | : | String... | Path names of the input files to be searched for the pattern; wildcards * and ? are supported; relative paths are resolved on the basis of the current working directory. | ||
<files> | : | java.io.File... | The input files to be searched for the pattern; relative paths are not resolved (use the string paths argument to enable relative path resolving based on the current working directory). | ||
<inputs> | : | org.unix4j.io.Input... | The inputs to be searched for the pattern. | ||
<args> | : | String... | String arguments defining the options and operands for the command. Options can be specified by acronym (with a leading dash "-") or by long name (with two leading dashes "--"). Operands other than the default "--pattern" and "--paths" operands have to be prefixed with the operand name (e.g. "--files" for subsequent file operand values). | ||
<options> | : | GrepOptions | The options defining the types of patterns and command behavior. |
Modifier and Type | Class and Description |
---|---|
static interface |
Grep.Interface<R>
Interface defining all method signatures for the "grep" command.
|
Modifier and Type | Field and Description |
---|---|
static GrepFactory |
Factory
Singleton
factory instance for the "grep" command. |
static String |
NAME
The "grep" command name.
|
static GrepOptionSets |
Options
|
public static final String NAME
public static final GrepOptionSets Options
i
, v
, F
, n
, c
, l
, x
.
-i | --ignoreCase | Match lines ignoring the case when comparing the strings, also known from Unix with its acronym 'i'. | |||
-v | --invertMatch | Invert the match result, that is, a non-matching line is written to the output and a matching line is not. This option is also known from Unix with its acronym 'v'. | |||
-F | --fixedStrings | Use fixed-strings matching instead of regular expressions. This is
usually faster than the standard regexp version.
(This option is ignored if a | |||
-n | --lineNumber | Prefix each line of output with the line number within its input file. | |||
-c | --count | Suppress normal output; instead print a count of matching lines for
each input file. With the -v , --invertMatch option,
count non-matching lines. | |||
-l | --matchingFiles | Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. | |||
-x | --wholeLine | Select only those matches that exactly match the whole line
excluding the terminating line ending.
(This option is ignored if a |
public static final GrepFactory Factory
factory
instance for the "grep" command.Copyright © 2024. All rights reserved.