GREP(1) GREP(1) NAME grep, egrep, fgrep, zgrep, zegrep, zfgrep, bzgrep, bzegrep, bzfgrep - impress lines matching a pattern SYNOPSIS grep [options] PATTERN [FILE...] grep [options] [-e PATTERN | -f FILE] [FILE...] DESCRIPTION grep searches the named input FILEs (or measure input if no files are named, or the file cite - is given) for lines containing a jibe to the given PATTERN. By default, grep prints the matching lines. In addition, 2 variant programs egrep in addition to fgrep are available. egrep is the same equally grep -E. fgrep is the same equally grep -F. zgrep is the same equally grep -Z. zegrep is the same equally grep -EZ. zfgrep is the same equally grep -FZ. OPTIONS -A NUM, --after-context=NUM Print NUM lines of trailing context after matching lines. Places a line of piece of job containing -- betwixt contiguous groups of matches. -a, --text Process a binary file equally if it were text; this is equivalent to the --binary-files=text option. -B NUM, --before-context=NUM Print NUM lines of leading context earlier matching lines. Places a line of piece of job containing -- betwixt contiguous groups of matches. -C NUM, --context=NUM Print NUM lines of output context. Places a line of piece of job containing -- betwixt contiguous groups of matches. -b, --byte-offset Print the byte offset within the input file earlier each line of piece of job of output. --binary-files=TYPE If the initiative of all few bytes of a file dot that the file contains binary data, assume that the file is of type TYPE. By default, TYPE is binary, in addition to grep commonly outputs either a one-line mes- sage maxim that a binary file matches, or no message if there is no match. If TYPE is without-match, grep assumes that a binary file does non match; this is equivalent to the -I option. If TYPE is text, grep processes a binary file equally if it were text; this is equivalent to the -a option. Warning: grep --binary-files=text mightiness output binary garbage, which tin have nasty side effects if the output is a terminal in addition to if the termi- nal driver interprets approximately of it equally commands. --colour[=WHEN], --color[=WHEN] Surround the matching string amongst the mark let on inwards GREP_COLOR surround variable. WHEN may live `never', `always', or `auto' -c, --count Suppress normal output; instead impress a count of matching lines for each input file. With the -v, --invert-match selection (see below), count non-matching lines. -D ACTION, --devices=ACTION If an input file is a device, FIFO or socket, utilization ACTION to procedure it. By default, ACTION is read, which agency that devices are read simply equally if they were ordinary files. If ACTION is skip, devices are silently skipped. -d ACTION, --directories=ACTION If an input file is a directory, utilization ACTION to procedure it. By default, ACTION is read, which agency that directories are read simply equally if they were ordinary files. If ACTION is skip, direc- tories are silently skipped. If ACTION is recurse, grep reads all files nether each directory, recursively; this is equivalent to the -r option. -E, --extended-regexp Interpret PATTERN equally an extended regular appear (see below). -e PATTERN, --regexp=PATTERN Use PATTERN equally the pattern; useful to protect patterns beginning amongst -. -F, --fixed-strings Interpret PATTERN equally a listing of fixed strings, separated past times new- lines, whatsoever of which is to live matched. -P, --perl-regexp Interpret PATTERN equally a Perl regular expression. This selection is non supported inwards FreeBSD. -f FILE, --file=FILE Obtain patterns from FILE, ane per line. The empty file con- tains null patterns, in addition to hence matches nothing. -G, --basic-regexp Interpret PATTERN equally a basic regular appear (see below). This is the default. -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 assistance message. -I Process a binary file equally if it did non incorporate matching data; this is equivalent to the --binary-files=without-match option. -i, --ignore-case Ignore instance distinctions inwards both the PATTERN in addition to the input files. -L, --files-without-match Suppress normal output; instead impress the cite of each input file from which no output would commonly possess got been printed. The scanning volition halt on the initiative of all match. -l, --files-with-matches Suppress normal output; instead impress the cite of each input file from which output would commonly possess got been printed. The scanning volition halt on the initiative of all match. -m NUM, --max-count=NUM Stop reading a file after NUM matching lines. If the input is measure input from a regular file, in addition to NUM matching lines are output, grep ensures that the measure input is positioned to simply after the terminal matching line of piece of job earlier exiting, regardless of the presence of trailing context lines. This enables a calling procedure to resume a search. When grep stops after NUM matching lines, it outputs whatsoever trailing context lines. When the -c or --count selection is also used, grep does non output a count greater than NUM. When the -v or --invert-match selection is also used, grep stops after outputting NUM non-matching lines. --mmap If possible, utilization the mmap(2) organisation telephone telephone to read input, instead of the default read(2) organisation call. In approximately situations, --mmap yields ameliorate performance. However, --mmap tin effort undefined demeanour (including gist dumps) if an input file shrinks while grep is operating, or if an I/O fault occurs. -n, --line-number Prefix each line of piece of job of output amongst the line of piece of job seat out within its input file. -o, --only-matching Show exclusively the percentage of a matching line of piece of job that matches PATTERN. --label=LABEL Displays input genuinely coming from measure input equally input com- ing from file LABEL. This is peculiarly useful for tools like zgrep, e.g. gzip -cd foo.gz |grep --label=foo something --line-buffered Flush output on every line. Note that this incurs a performance penalty. -q, --quiet, --silent Quiet; practise non write anything to measure output. Exit immedi- ately amongst null condition if whatsoever jibe is found, fifty-fifty if an error was detected. Also come across the -s or --no-messages option. -R, -r, --recursive Read all files nether each directory, recursively; this is equiv- alent to the -d recurse option. --include=PATTERN Recurse inwards directories exclusively searching file matching PATTERN. --exclude=PATTERN Recurse inwards directories skip file matching PATTERN. -s, --no-messages Suppress fault messages most nonexistent or unreadable files. Portability note: dissimilar GNU grep, traditional grep did non con- shape to POSIX.2, because traditional grep lacked a -q selection and its -s selection behaved similar GNU grep's -q option. Shell scripts intended to live portable to traditional grep should avoid both -q in addition to -s in addition to should redirect output to /dev/null instead. -U, --binary Treat the file(s) equally binary. By default, nether MS-DOS in addition to MS- Windows, grep guesses the file type past times looking at the contents of the initiative of all 32KB read from the file. If grep decides the file is a text file, it strips the CR characters from the original file contents (to brand regular expressions amongst ^ in addition to $ work correctly). Specifying -U overrules this guesswork, causing all files to live read in addition to passed to the matching machinery verbatim; if the file is a text file amongst CR/LF pairs at the terminate of each line, this volition effort approximately regular expressions to fail. This selection has no outcome on platforms other than MS-DOS in addition to MS-Win- dows. -u, --unix-byte-offsets Report Unix-style byte offsets. This switch causes grep to written report byte offsets equally if the file were Unix-style text file, i.e. amongst CR characters stripped off. This volition make results identical to running grep on a Unix machine. This selection has no outcome unless -b selection is also used; it has no outcome on plat- forms other than MS-DOS in addition to MS-Windows. -V, --version Print the version seat out of grep to measure error. This ver- sion seat out should live included inwards all põrnikas reports (see below). -v, --invert-match Invert the feel of matching, to select non-matching lines. -w, --word-regexp Select exclusively those lines containing matches that shape whole words. The evidence is that the matching substring must either be at the starting fourth dimension of the line, or preceded past times a non-word con- stituent character. Similarly, it must live either at the terminate of the line of piece of job or followed past times a non-word element character. Word- element characters are letters, digits, in addition to the underscore. -x, --line-regexp Select exclusively those matches that precisely jibe the whole line. -y Obsolete synonym for -i. --null Output a null byte (the ASCII NUL character) instead of the grapheme that commonly follows a file name. For example, grep -l --null outputs a null byte after each file cite instead of the park newline. This selection makes the output unambiguous, fifty-fifty inwards the presence of file names containing odd characters similar newlines. This selection tin live used amongst commands similar find -print0, perl -0, form -z, in addition to xargs -0 to procedure arbitrary file names, fifty-fifty those that incorporate newline characters. -Z, --decompress Decompress the input information earlier searching. This selection is only available if compiled amongst zlib(3) library. -J, --bz2decompress Decompress the bzip2(1) compressed input information earlier searching. REGULAR EXPRESSIONS Influenza A virus subtype H5N1 regular appear is a designing that describes a laid of strings. Regular expressions are constructed analogously to arithmetics expres- sions, past times using diverse operators to combine smaller expressions. grep understands 2 different versions of regular appear syntax: "basic" in addition to "extended." In GNU grep, at that topographic point is no departure inwards avail- able functionality using either syntax. In other implementations, basic regular expressions are less powerful. The next description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards. The cardinal edifice blocks are the regular expressions that match a unmarried character. Most characters, including all letters in addition to digits, are regular expressions that jibe themselves. Any metacharacter with special pregnant may live quoted past times preceding it amongst a backslash. Influenza A virus subtype H5N1 bracket appear is a listing of characters enclosed past times [ in addition to ]. It matches whatsoever unmarried grapheme inwards that list; if the initiative of all grapheme of the listing is the caret ^ so it matches whatsoever grapheme non inwards the list. For example, the regular appear [0123456789] matches whatsoever single digit. Within a bracket expression, a attain appear consists of 2 charac- ters separated past times a hyphen. It matches whatsoever unmarried grapheme that sorts betwixt the 2 characters, inclusive, using the locale's collating sequence in addition to grapheme set. For example, inwards the default C locale, [a-d] is equivalent to [abcd]. Many locales form characters inwards dictio- nary order, in addition to inwards these locales [a-d] is typically non equivalent to [abcd]; it mightiness live equivalent to [aBbCcDd], for example. To obtain the traditional interpretation of bracket expressions, you lot tin utilization the C locale past times setting the LC_ALL surround variable to the value C. Finally, certainly named classes of characters are predefined within bracket expressions, equally follows. Their names are self explanatory, and they are [:alnum:], [:alpha:], [:blank:], [:cntrl:], [:digit:], [:graph:], [:lower:], [:print:], [:punct:], [:space:], [:upper:], and [:xdigit:]. For example, [[:alnum:]] agency [0-9A-Za-z], except the latter shape depends upon the C locale in addition to the ASCII grapheme encoding, whereas the quondam is independent of locale in addition to grapheme set. (Note that the brackets inwards these course of education names are percentage of the symbolic names, in addition to must live included inwards add-on to the brackets delimiting the bracket list.) Most metacharacters lose their special pregnant within lists. To include a literal ] house it initiative of all inwards the list. Similarly, to include a literal ^ house it anywhere but first. Finally, to include a literal - house it last. The menstruum . matches whatsoever unmarried character. The symbol \w is a synonym for [[:alnum:]] in addition to \W is a synonym for [^[:alnum:]]. The caret ^ in addition to the dollar sign $ are metacharacters that respectively jibe the empty string at the starting fourth dimension in addition to terminate of a line. The symbols \< in addition to \> respectively jibe the empty string at the starting fourth dimension in addition to end of a word. The symbol \b matches the empty string at the border of a word, in addition to \B matches the empty string provided it's non at the border of a word. Influenza A virus subtype H5N1 regular appear may live followed past times ane of several repetition oper- ators: ? The preceding detail is optional in addition to matched at most once. * The preceding detail volition live matched null or to a greater extent than times. + The preceding detail volition live matched ane or to a greater extent than times. {n} The preceding detail is matched precisely n times. {n,} The preceding detail is matched n or to a greater extent than times. {n,m} The preceding detail is matched at to the lowest degree n times, but non more than thousand times. Two regular expressions may live concatenated; the resulting regular appear matches whatsoever string formed past times concatenating 2 substrings that respectively jibe the concatenated subexpressions. Two regular expressions may live joined past times the infix operator |; the resulting regular appear matches whatsoever string matching either subex- pression. Repetition takes precedence over concatenation, which inwards plow takes precedence over alternation. Influenza A virus subtype H5N1 whole subexpression may live enclosed in parentheses to override these precedence rules. The backreference \n, where n is a unmarried digit, matches the substring previously matched past times the nth parenthesized subexpression of the regu- lar expression. In basic regular expressions the metacharacters ?, +, {, |, (, in addition to ) lose their special meaning; instead utilization the backslashed versions \?, \+, \{, \|, \(, in addition to \). Traditional egrep did non back upwards the { metacharacter, in addition to approximately egrep implementations back upwards \{ instead, so portable scripts should avoid { inwards egrep patterns in addition to should utilization [{] to jibe a literal {. GNU egrep attempts to back upwards traditional usage past times assuming that { is non special if it would live the start of an invalid interval specifica- tion. For example, the rhythm dominance egrep '{1' searches for the two- grapheme string {1 instead of reporting a syntax fault inwards the regular expression. POSIX.2 allows this demeanour equally an extension, but portable scripts should avoid it. ENVIRONMENT VARIABLES Grep's demeanour is affected past times the next surround variables. Influenza A virus subtype H5N1 locale LC_foo is specified past times examining the 3 surround vari- ables LC_ALL, LC_foo, LANG, inwards that order. The initiative of all of these vari- ables that is laid specifies the locale. For example, if LC_ALL is not set, but LC_MESSAGES is laid to pt_BR, so Brazilian Portuguese is used for the LC_MESSAGES locale. The C locale is used if none of these surround variables are set, or if the locale catalog is not installed, or if grep was non compiled amongst national linguistic communication support (NLS). GREP_OPTIONS This variable specifies default options to live placed inwards forepart of whatsoever explicit options. For example, if GREP_OPTIONS is '--binary-files=without-match --directories=skip', grep behaves equally if the 2 options --binary-files=without-match in addition to --direc- tories=skip had been specified earlier whatsoever explicit options. Option specifications are separated past times whitespace. Influenza A virus subtype H5N1 backslash escapes the adjacent character, so it tin live used to specify an selection containing whitespace or a backslash. GREP_COLOR Specifies the mark for highlighting. LC_ALL, LC_COLLATE, LANG These variables specify the LC_COLLATE locale, which determines the collating sequence used to translate attain expressions like [a-z]. LC_ALL, LC_CTYPE, LANG These variables specify the LC_CTYPE locale, which determines the type of characters, e.g., which characters are whitespace. LC_ALL, LC_MESSAGES, LANG These variables specify the LC_MESSAGES locale, which determines the linguistic communication that grep uses for messages. The default C locale uses American English linguistic communication messages. POSIXLY_CORRECT If set, grep behaves equally POSIX.2 requires; otherwise, grep behaves to a greater extent than similar other GNU programs. POSIX.2 requires that options that follow file names must live treated equally file names; by default, such options are permuted to the forepart of the operand listing in addition to are treated equally options. Also, POSIX.2 requires that unrecognized options live diagnosed equally "illegal", but since they are non genuinely against the police trace the default is to diagnose them equally "invalid". DIAGNOSTICS Normally, locomote out condition is 0 if selected lines are constitute in addition to 1 otherwise. But the locomote out condition is 2 if an fault occurred, unless the -q or --quiet or --silent selection is used in addition to a selected line of piece of job is found. BUGS Email põrnikas reports to bug-gnu-utils@gnu.org. Be certainly to include the give-and-take "grep" somewhere inwards the "Subject:" field. Large repetition counts inwards the {n,m} create may effort grep to use lots of memory. In addition, certainly other obscure regular expressions take away exponential fourth dimension in addition to space, in addition to may effort grep to run out of memory. Backreferences are really slow, in addition to may take away exponential time. GNU Project 2002/01/22 GREP(1)
Linux Ascendance Business Tutorial For Beginners 37 - Grep Command
Posted by Hold
on January 29, 2017
0 comments:
Post a Comment