"^" : 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. POJ:3421-X-factor Chains(因式分解)(全排列)

    X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7986 Accepted: 2546 Descr ...

  2. HTML中body相关标签-03

    今日主要内容: 列表标签 <ul>.<ol>.<dl> 表格标签 <table> 表单标签 <fom> 一.列表标签 列表标签分为三种. 1 ...

  3. Still unable to dial persistent://blog.csdn.net:80 after 3 attempts

    动不动电脑有些网站打不开了,还报错: Still unable to dial persistent://blog.csdn.net:80 after 3 attempts 为什么呢? 是dns坏了? ...

  4. 远程 RADIUS 服务器组

    远程 RADIUS 服务器组 远程 RADIUS 服务器组是包含一个或多个 RADIUS 服务器的已命名的组.IAS 用作 RADIUS 请求消息的 RADIUS 代理时,必须指定远程 RADIUS ...

  5. Hyper-V在线调整虚拟硬盘大小

    从Windows Server 2012 R2 开始,可以在线调整虚拟硬盘的大小了,这意味着当虚拟硬盘不够用时,我们在虚拟机运行的情况下直接扩展虚拟硬盘容量了.有人说这个有什么用?当然,实验室情况下, ...

  6. 批量修改Linux文件夹下所有文件大小写

    小写转大写: [zengs@SYS SOS]$ for cpplive in *; do mv $cpplive `echo $cpplive|tr [a-z] [A-Z]`; done 大写转小写: ...

  7. Pascal小游戏 贪吃蛇

    一段未完成的Pascal贪吃蛇 说这段代码未完成其实是没有源代码格式化,FP中一行最多只有255字符宽. uses crt; const screenwidth=50; screenheight=24 ...

  8. 【APUE】Chapter9 Process Relationships

    这一章看的比较混乱,可能是因为例子少:再有就是,这一章就是一个铺垫的章节. 9.2 terminal logins 啥叫termnial? 我感觉书上的terminal指的更可能是一些物理设备(key ...

  9. android SharedPreferences 浅析

    1. 介绍:SharedPreferences 的作用是使用键值对的方式存储数据.且支持多种不同的数据类型存储: Android数据持久化方法中最简单的一种,即使用Preferences的键值对存储方 ...

  10. python 学习分享-paramiko模块

    paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Solaris, BS ...