grep

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

grep is a tool for searching text files with regular expressions. Its name is a play on the ed command g/re/p which would globally search a document for a given regular expression and print the results.

There are multiple implementations of grep. By default, Gentoo installs GNU Grep (sys-apps/grep), as part of the @system set. GNU Grep can be configured to behave as required by POSIX via the POSIXLY_CORRECT environment variable; refer to the GNU grep(1) man page for further information.

Installation

USE flags

USE flags for sys-apps/grep GNU regular expression matcher

+egrep-fgrep Install deprecated 'egrep' and 'fgrep' wrappers for 'grep -E' and 'grep -F' respectively. GNU grep 3.8 onwards warns about their usage by default, but the versions installed by this flag do not. No deprecation warnings are emitted when this flag is enabled.
nls Add Native Language Support (using gettext - GNU locale utilities)
pcre Add support for Perl Compatible Regular Expressions
static !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
verify-sig Verify upstream signatures on distfiles

Emerge

Install sys-apps/grep:

root #emerge --ask sys-apps/grep

Configuration

Environment variables

  • GREP_COLOR (deprecated) colorizes matching text, by default this is set to 01;31 which is a bold red.
  • GREP_COLORS sets the color of various parts of output, not just matches.
  • LC_ALL, LC_COLLATE, LANG specify the locale for the collating sequence.
  • LC_ALL, LC_CTYPE, LANG determines the encoding of characters and their attributes.
  • LC_ALL, LC_MESSAGES, LANG determines the language grep uses for messages.
  • POSIXLY_CORRECT treat all input after a file name as an additional file name among other things.

Usage

See also
For more information see devmanual.

Invocation

To see grep usage information:

user $grep --help

Removal

Unmerge

Remove sys-apps/grep:

root #emerge --ask --depclean --verbose sys-apps/grep

See also

  • awk — a scripting language for data extraction
  • ed — a line-based text editor with support for regular expressions
  • Perl — a general purpose interpreted programming language with a powerful regular expression engine.
  • Raku — a high-level, general-purpose, and gradually typed programming language with low boilerplate objects, optionally immutable data structures, and an advanced macro system.
  • ripgrep — search tool that can recursively search directories for regex search patterns
  • sed — a program that uses regular expressions to programmatically modify streams of text