Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

【备忘】grep常用用法 #6

Open
Labels
@codezyc

Description

输出行号

grep -n "boo" a_file

反向查找,即显示没有'搜索字符串'内容的那行

grep -v "boo" a_file

统计一共有多少行匹配了

grep -c "boo" a_file

仅显示匹配到的文件名

grep -l "boo" *

匹配忽略大小写

grep -i "BOO" a_file

完全精确匹配

grep -x "boo" a_file

根据正则表达式进行匹配

grep "e$" a_file
grep -E "boots?" a_file
grep -E "boot|boots" a_file

高亮显示匹配内容

grep --color=always "boo" xxx

显示匹配到字符那行的后面n行

grep -A2 "mach" a_file

显示匹配到字符那行的前面n行

grep -B2 "mach" a_file

显示匹配到字符那行的前后n行

grep -C2 "mach" a_file

递归使用grep

grep -r "192.168.1.5" /etc/

强制只输出那些仅仅包含那个整个单词的行

grep -w "boo" 1.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /