1. 基本概念
grep(缩写来自Globally search a Regular Expression and Print)是一种强大的文本搜索工具,它能使用特定模式匹配(包括正则表达式)搜索文本,并默认输出匹配行。Unix的grep家族包括grep、egrep和fgrep。Windows系统下类似命令FINDSTR。
1.1. 基本语法
搜索标准输出(即文本流)
$ grep [options] search_string
在文件中搜索确切的字符串:
$ grep [options] search_string path/to/file
打印 myfile.txt 中包含字符串“hello”的行
$ grep 'hello' myfile.txt
1.2. 参数选项
选项 |