Linux_grep命令使用
最近在学Linux,发现grep命令很常用,所以记录一下,方便之后查询; grep命令常见用法 1、字符串搜索: 在文件中搜索一个单词,命令会返回一个包含 “match_pattern” 的文本行: grep match_pattern file_name grep "match_pattern" file_name 例子: 2、在多个文件中查找字符串: grep "match_pattern" file_1 file_2 file_3 ... 例子: 3、输出除之外的所有行 -v 选项: grep -v "match_pattern" file_name 例子: 4、标记匹配颜色 —color=auto 选项: grep "match_pattern" file_name --color=auto 例子: 5、使用正则表达式: 使用正则表达式 -E 选项: grep -E "[1-9]+" # 或 egrep "[1-9]+" 使用正则表达式 -P 选项: grep -P "(\d{3}\-){2}\d{4}" file_name 只输出文件中匹配到的部分 -o 选项: echo this is a test line. | grep -o -E "[a-z]+\." line. echo this is a test line. | egrep -o "[a-z]+\." line. 6、统计文件或者文本中包含匹配字符串的行数: -c 选项: ...