`
xiaoer_1982
  • 浏览: 1820866 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

UNIX® Shells by Example, Third Edition笔记1

阅读更多
1.grep 's Regular Expression Metacharacters(Which I always dismissed~)
[^] Matches one character not in the set '[^A–K]ove' Matches lines not containing a character in the range A through K, followed by ove.
\< Beginning-of-word anchor '\<love' Matches lines containing a word that begins with love.
\> End-of-word anchor 'love\>' Matches lines containing a word that ends with love.
\(..\) Tags matched characters '\(love\)ing' Tags marked portion in a register to be remembered later as number 1. To reference later, use \1 to repeat the pattern. May use up to nine tags, starting with the first tag at the left-most part of the pattern. For example, the pattern love is saved in register 1 to be referenced later as \1.
x\{m\} x\{m,\} x\{m,n\} [a] Repetition of character x: m times, at least m times, or between m and n times 'o\{5\}' 'o\{5,\}' 'o\{5,10\}' Matches if line has 5 occurences of o , at least 5 occurences of o , or between 5 and 10 occurrences of o .


EXPLANATION

Prints the line if it contains the word north. The \< is the beginning-of-word anchor, and the \> is the end-of-word anchor.

4.grep 's Options

OptionWhat It Does
–b Precedes each line by the block number on which it was found. This is sometimes useful in locating disk block numbers by context.
–c Displays a count of matching lines rather than displaying the lines that match.
–h Does not display filenames.
–i Ignores the case of letters in making comparisons (i.e., upper-- and lowercase are considered identical).
–l Lists only the names of files with matching lines (once), separated by newline characters.
–n Precedes each line by its relative line number in the file.
–s Works silently, that is, displays nothing except error messages. This is useful for checking the exit status.
–v Inverts the search to display only lines that do not match.
–w Searches for the expression as a word, as if surrounded by \< and \>. This applies to grep only. (Not all versions of grep support this feature; e.g., SCO UNIX does not.)



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics