(31) grep command Detailed: Find the file contents

1.grep command does not require the entire contents of the listed files, but to find those that contain the specified information from the file.
  grep command can be one or more files, search for a particular character mode (that is, regular expressions), this mode can be a single character string, word or sentence.
  A regular expression is a description of a set of pattern strings, constitute regular expressions mimic the mathematical expression, by using a smaller operator expressions into a new expression. Regular expressions can be some of the text in plain text, it can be used to generate special characters mode. In order to further define a search pattern, grep command supports these types of regular expression metacharacters as shown in Table 1 (ie wildcard).

  c * matches 0 (i.e., blank) or more characters c (c is any character).
  The match any one character, and only one character.
  [XYZ] match any one character in the square brackets.
  [^ xyz] matches all characters except characters in brackets.
  ^ Lock beginning of the line.
  End of the line $ locked.  

  Note that, in basic regular expressions, such as the wildcard *, +, {, |, (and), etc., have lost their original meaning, and to restore their original meaning, will have to be added before the Anti slash \, as \ *, \ +, \ {, \ |, \ (and \).

  grep command is used to search for a specific pattern or in each file (or specific output), when used grep, each row contains the contents of the character mode is designated, it is printed (displayed) on the screen, but using grep command It does not change the contents of the file.

  The basic format grep command is as follows:
  [root @ localhost ~] # grep [options] pattern filename

  The model here, either character (string), or a regular expression.

  grep command options and common meaning of
  the number of lines contained in the file mode -c list only.
  -i ignore patterns in letter case.
  -l List file names with matching rows.
  -n lists the line number in front of each line.
  -v lists the line does not match the pattern.
  -w the expression as a complete single character to search, ignore those parts of matching lines.
  Note that if a plurality of file search, the search results grep command only files matching pattern found in the file name; if single search file, grep command will display the results of each row containing a matching pattern.

 

Guess you like

Origin www.cnblogs.com/xinghen1216/p/11316925.html