grep常用命令整理
grep命令简介
grep是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。
grep家族
grep家族包括grep、egrep和fgrep:egrep是grep的扩展,支持更多的re元字符;fgrep就是fixed grep或fast grep。
工作机制简要介绍
grep在一个或多个文件中搜索字符串模板。如果模板包括空格,则必须被引用,模板后的所有字符串被看作文件名。搜索的结果被送到标准输出,不影响原文件内容。
grep常用命令整理
1、从单个文件中查找指定的字符串
grep "this" demo_file
2、从多个文件中查找指定的字符串
grep "this" demo_*
3、查询且忽略大小写
grep -i
4、在文件中匹配正则表达式
基础正则表达式:
1. ? The preceding item is optional and matched at most once.
2. * The preceding item will be matched zero or more times.
3. + The preceding item will be matched one or more