The Backslash Character and Special Expressions The symbols \< and \> respectively match the empty string at the beginning and end of a word. The symbol \b matches the empty string at the edge of a word, and \B
^[[:space:]]*$ 空白行 ^PATTERN$ 用于模式匹配整行 \<PATTERN\> 匹配整个单词 \| 或者 () 将多个字符捆绑在一起,当作一个整体处理 后向引用:\(string\string2\)\) 1\:string\(string2\) 2\:string2
\(string\) :将string作为一个整体方便后面引用 \1 :引用第1个左括号及其对应的右括号所匹配的内容。 \2 :引用第2个左括号及其对应的右括号所匹配的内容。 \n :引用第n个左括号及其对应的右括号所匹配的内容。 grep常用例子 -例1 在文件中查找模式(单词) 在/etc/passwd文件中查找单词“linuxtechi” grep...
-h或--no-filename 在显示符合范本样式的那一列之前,不标示该列所属的文件名称。 -H或--with-filename 在显示符合范本样式的那一列之前,表示该列所属的文件名称。 -i或--ignore-case 忽略字符大小写的差别。 -l或--file-with-matches 列出文件内容符合指定的范本样式的文件名称。 -L或--files-without-ma...
\(string\) :将string作为一个整体方便后面引用 \1 :引用第一个左括号及其对应的右括号所匹配的内容。 \2 :引用第二个左括号及其对应的右括号所匹配的内容。 eg5:我想在hello.c文件中匹配行首以 l 开头 e 结尾的单词(比如 like,love等),行尾以相同的单词结尾。(比如这种行:large dog is a dog that is...
'--group-separator=STRING' 当使用'-A', '-B' or '-C'时,使用STRING替代默认的组分隔符。 (注:组分隔符表示匹配到的内容的上下文。例如"-A 2",在某行匹配到时,还将输出后两行,这是一个组。下一次匹配成功时,如果是在该组之后行匹配上的,则这两组中间默认使用"--"分隔) ...
good/test2:test the string. test2:grep test for test2:used to test the test3:grep test for test3:used to test the testFile:this file used for test the 这个应该是最常使用的命令了。-r选项的意思就是递归搜索子目录的意思。 查找test并给结果中匹配的字符串加上颜色 ...
根据字符串模式提取文本行 grep [选项] ‘匹配模式’ 文本文件 常用命令选项 -v,去反匹配 -i,...
grep - print lines matching a patterngrep [OPTIONS] PATTERN [FILE...] grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
Surround the matching string with the marker find inGREP_COLORenvironment variable. WHEN may be `never', `always', or `auto' -c,--count Suppress normal output; instead print a count of matching lines for each input file. With the-v,--invert-matchoption (see below), count non-matching ...