fgrep
rose1 发表于 2020-09-12 06:21浏览次数:
在类Unix操作系统,fgrep一样的定点命令搜索字符 字符串中的一个或多个文件。“固定字符”表示字符串按字面意义进行解释- 元字符不存在,因此无法使用正则表达式。
本文档介绍fgrep的GNU / Linux版本。
On Unix-like operating systems, the fgrep command searches for fixed-character strings in a file or files. "Fixed-character" means the string is interpreted literally — metacharacters do not exist, and therefore regular expressions cannot be used.
This document covers the GNU/Linux version of fgrep.
目录:
1 fgrep 运行系统环境
2 fgrep 说明
3 fgrep 语法
4 fgrep 例子
fgrep 运行系统环境
fgrep 说明
当您需要搜索包含很多正则表达式元字符的字符串(例如“ $ ”,“ ^ ”等)时,fgrep很有用。通过指定搜索字符串包含固定字符,您无需对每个字符进行转义用反斜杠。
如果您的字符串包含换行符,则每行将被视为要在搜索中匹配的单个固定字符字符串。
运行fgrep与使用-F选项运行grep相同。
fgrep is useful when you need to search for strings which contain lots of regular expression metacharacters, such as "$", "^", etc. By specifying that your search string contains fixed characters, you don't need to escape each of them with a backslash.
If your string contains newlines, each line will be considered an individual fixed-character string to be matched in the search.
Running fgrep is the same as running grep with the -F option.
fgrep 语法
fgrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list]
[-f pattern-file] [pattern] [file]
选件
-b
|
在每行之前加上找到它的块号。这对于按上下文查找块编号很有用(第一个块为0)。
|
-c
|
仅打印包含模式的行数。
|
-h
|
搜索多个文件时禁止打印文件。
|
-i
|
在比较过程中,忽略大小写区分。
|
-l
|
一次打印带有匹配行的文件名,并用换行符分隔。找到多个模式时不重复文件名。
|
-n
|
在文件中,每行之前应加上行号(第一行是1)。
|
-s
|
以静默方式工作,即除错误消息外什么也不显示。这对于检查错误状态很有用。
|
-v
|
打印除包含模式的行以外的所有行。
|
-x
|
仅打印完全匹配的行。
|
-e pattern_list
|
在模式列表中搜索字符串(当字符串以“ - ” 开头时很有用)。
|
-f 模式文件
|
从pattern-file中获取模式列表。
|
模式
|
指定在搜索输入期间要使用的模式。
|
文件
|
要搜索模式的文件的路径名。如果未指定文件操作数,则将使用标准输入。
|
fgrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list]
[-f pattern-file] [pattern] [file]
Options
-b
|
Precede each line by the block number on which it was found. This can be useful in locating block numbers by context (first block is 0).
|
-c
|
Print only a count of the lines that contain the pattern.
|
-h
|
Suppress printing of files when searching multiple files.
|
-i
|
Ignore upper/lower case distinction during comparisons.
|
-l
|
Print the names of files with matching lines once, separated by new-lines. Does not repeat the names of files when the pattern is found more than once.
|
-n
|
Precede each line by its line number in the file (first line is 1).
|
-s
|
Work silently, that is, display nothing except error messages. This is useful for checking the error status.
|
-v
|
Print all lines except those that contain the pattern.
|
-x
|
Print only lines matched entirely.
|
-e pattern_list
|
Search for a string in pattern-list (useful when the string begins with a "-").
|
-f pattern-file
|
Take the list of patterns from pattern-file.
|
pattern
|
Specify a pattern to be used during the search for input.
|
file
|
A path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used.
|
fgrep 例子
fgrep "support" myfile.txt
在myfile.txt文件中搜索“ support ” 。
fgrep "support" myfile.txt
Search for "support" in the file myfile.txt.