diff --git a/command/grep.md b/command/grep.md index bfa45e3466..f58e54cdc3 100644 --- a/command/grep.md +++ b/command/grep.md @@ -28,6 +28,7 @@ grep -l --file-with-matches # 列出文件内容符合指定的范本样式的文件名称。 -L --files-without-match # 列出文件内容不符合指定的范本样式的文件名称。 -n --line-number # 在显示符合范本样式的那一列之前,标示出该列的编号。 +-P --perl-regexp # PATTERN 是一个 Perl 正则表达式 -q --quiet或--silent # 不显示任何信息。 -R/-r --recursive # 此参数的效果和指定“-d recurse”参数相同。 -s --no-messages # 不显示错误信息。 @@ -95,6 +96,12 @@ grep -E "[1-9]+" # 或 egrep "[1-9]+" ``` +使用正则表达式 **-P** 选项: + +```shell +grep -P "(\d{3}\-){2}\d{4}" file_name +``` + 只输出文件中匹配到的部分 **-o** 选项: