What is Grep

W

Grep is a UNIX text search command. The name comes from the first letters of “global/regular expression/print”, which is a series of commands for editors such as ed. The “grep” command searches for files in or standard inputs that correspond to a regular expression and writes them to the standard output.

There are countless implementations and variations of the grep program available for many operating systems. Some of the first variants of grep were egrep and fgrep.

The Global Regular Expression Print family lets you search for a string, specified by a regular expression, in a list of files. The result of the order can be displayed or it can serve as input for another UNIX command. The three commands in the grep family are: grep, fgrep and egrep. They differ in the generality of the search expression and the search speed. The grep command searches for regular expressions specified by the ed editor, the search algorithm being compact and non-deterministic. The fgrep command (Fast grep) searches for fixed strings, the search algorithm being compact and fast. The egrep command (Extended Grep) searches for generalized regular expressions, the search algorithm being fast and deterministic.

Normally, fgrep is used to search for fixed strings and egrep otherwise, except for string searches that repeat when using grep. Regular expressions used by grep use ‘\ (‘ and ‘\)’ to define groups, allowing for repeat group search. Instead, the regular expressions used by egrep do not use the ‘\’ symbol when defining groups and do not allow repeating search for guppies.

1. Order syntax:

grep [options] sir [file (s)]

egrep [options] [sir] [file (s)]

fgrep [options] [sir] [file (s)]

2. Offers affecting search:

-w Search is done by word (BSD Unix).

-v Selects lines that do not contain the string.

– Equivalent treatment of large and small letters.

3. Options Affecting Output:

-c Only indicate the number of lines found.

-l Indicates only the names of the files containing the specified string.

-n Each line indicates the file name and line number.

-s In version V (grep only) it suppresses the display of error messages.

4. The fgrep and egrep commands accept the options:

-e Sir Used to search for strings beginning with ‘-‘.

-f Fis Reads the list of regular expressions in the file.

These are just a few options supported by the grep command. these examples can be used by beginners to search inside the files. The grep command shows its value used with regular expressions, but this involves some more experience. To learn more about grep and its options use grep man.

The bell is a regular expression. A regular expression is a sequence of characters in which some characters have special semantics. The character “\” avoids the special significance of a character, “…” avoids any character less than $ and ‘…’ and with ‘…’ any character is avoided.

Characters of special significance:

1) “.” – any character
2) [character_character] – any character in the string
   [c1 – c2] – any character between c1 and c2 in order
        lexicographical
   [^ sir_caractere] – his negation [sir_caractere]
3) “^” – if the first character in the template signifies the beginning of the line
     eg: $ grep ^ if fis1 fis2   displays the lines in fis1 and fis2 starting with if
       $ grep if fis1 fis2  displays all lines in fis1 and fis2 that contain the “if”
4) “$” – if the last character in the pattern signifies the end of the line
     eg: $ grep be $ fis1 fis2 >  displays the lines in fis1 and fis2 ending with fi
5) \ <- means the beginning of a word (a cuvette consists of letters, figures or -, any other character is considered a separator)
6) -> signifies the word
7) * – Repeats the previously interpreted character as regular expression as many times as possible
8) \ {n \} – where n is a number between 0 and 255 repeats the previous expression of exactly n times
9) \ {n, \} – repeats the previous regular expression at least n times
10) \ {n, m \} – repeats the previous regular expression at least n times and at most times
11) \ (expr-regular \) <=> expr-regular
12) \ n – where n is between 0 and 512
    \ n replaces a string with which the regular expression found in brackets has been replaced.
      eg: grep ‘^ \ (. * \) \ (. * \) \ 1 $’ fis1 > displays all lines that begin and end with the same word separator being space and contains more than two words.

Recent Posts

Archives

Categories