0
点赞
收藏
分享

微信扫一扫

linux egrep命令使用示例


egrep命令是grep命令的扩展版本,支持更多的正则表达式语法,并且可以查询多个文件。

以下是egrep命令的使用示例:

在文件中查找包含“hello”的行:

egrep "hello" file.txt

查找包含“hello”或“world”的行:

egrep "hello|world" file.txt

查找以“hello”开头的行:

egrep "^hello" file.txt

查找以“world”结尾的行:

egrep "world$" file.txt

查找包含“hello”并且以“world”结尾的行:

egrep "hello.*world$" file.txt

在多个文件中查找包含“hello”的行:

egrep "hello" file1.txt file2.txt file3.txt

将查找结果输出到一个新文件中:

egrep "hello" file.txt > result.txt

在文件中查找不包含“hello”的行:

egrep -v "hello" file.txt

显示每行包含匹配项的行号:

egrep -n "hello" file.txt

查找包含“hello”的行,并显示匹配的文本:

egrep -o "hello" file.txt

以上是egrep命令的一些常见用法示例,可以根据需要选择合适的语法进行查询。


举报

相关推荐

0 条评论