"^" : Start of Line anchor

"." : Matches any single character except the newline character.

"*" : Matches the preceding character 0 or more times.

Application_1

test file

if_0        // no white space, no tab space
if_1 // a tab space
if_2 // two white space

command :

$ grep "^if" test
if_0

Conclusion :

^ is used to match the first column string

Application_2

test file

if_0 CROSS_COMPILE
if_1 CROSS_COMPILE
if_2 CROSS_COMPILE

command_1 :

$ grep -rns "^if.*CROSS" test
1:if_0 CROSS_COMPILE

command_2 :

$ grep -rns ".*if.*CROSS" test
1:if_0 CROSS_COMPILE
3: if_1 CROSS_COMPILE
4: if_2 CROSS_COMPILE

Conclusion :

For coding style, programmer place white or tab space in front of if.

If you want to find if as start, have to use ".*"

Application_3

test file

aaa1
aaa1
bbb2
bbb2
ccc3
ccc3

command_1 :

$ grep "^bbb" test
bbb2
bbb2

command_2 :

$ grep "^[^bbb]" test
aaa1
aaa1
ccc3
ccc3

随机推荐

  1. 2,版本控制git --分支

    有人把 Git 的分支模型称为它的`‘必杀技特性’',也正因为这一特性,使得 Git 从众多版本控制系统中脱颖而出. 为何 Git 的分支模型如此出众呢? Git 处理分支的方式可谓是难以置信的轻量, ...

  2. 9.3centos7安装python3 以及tab补全功能

    1.安装python3 1.1下载python源码包 网址:https://www.python.org/downloads/release/python-362/ 下载地址:https://www. ...

  3. echart图表展示数据-简单的柱状图

    话不多说,先上几张效果图 给大家看看 1:echart所用到的文件包需要事先引入好具体可见 http://echarts.baidu.com/doc/start.html 2:本例中所有的数据都是通过 ...

  4. Win Server 8中的利器:微软在线备份服务

    微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了.     微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...

  5. python考点

    Python考点 1.Python类继承,内存管理(阿里) 答:内存管理机制包括:引用计数机制,垃圾回收机制,内存池机制 a = 1,1就是对象,a就是引用,引用a指向对象1. 2.Python装饰器 ...

  6. dynamic基元类型与隐式类型的局部变量var

    dynamic代码示例 using System; using System.Collections.Generic; using System.Linq; using System.Text; na ...

  7. Windows下安装PHP及开发环境配置

    一.Apache 因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 1. 进入Apachelounge官方下载地址:http://www. ...

  8. Python IO关于mode参数的问题

    关于open()的mode参数: 'r':读 'w':写 'a':追加 'r+' == r+w(可读可写,文件若不存在就报错(IOError)) 'w+' == w+r(可读可写,文件若不存在就创建) ...

  9. 孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库

    孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第二 ...

  10. centos7系列问题

    一.CentOS7.1查看ip route有两条路由规则 1.metric值是指到达目的地需要的跳数,是表达该条路由连接质量的指标.当有多条到达相同目的地的路由记录时,路由器会采用metric值小的那 ...