grep and regular expression --- ^ . *
"^" : 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
随机推荐
- POJ:3268-Silver Cow Party
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26184 Accepted: 11963 De ...
- python-6面向对象编程
1-类和实例 class Student(object): def __init__(self, name, score):# _init__方法的第一个参数永远是self,表示创建的实例本身 sel ...
- perl连接mysql数据库
首先需要安装 ppm install DBD::mysql use strict; use DBI; my $host = "localhost"; # 主机地址 my $driv ...
- MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':ge
数据库表里命名有这个字段,可怎么就是报错呢,大神的解释: 加上之后立马好用!!!
- Ubuntu 14.10 配置JDK + J2EE
本文仅作为本人在Ubuntu 14.10下安装JDK + J2EE的一个记录: 安装JDK 从Oracle的官网下载jdk-7u75-linux-x64.tar.gz 将jdk-7u75-linux- ...
- 4 Django简介
MVC与MTV模型 MVC Web服务器开发领域里著名的MVC模式,所谓MVC就是把Web应用分为模型(M),控制器(C)和视图(V)三层,他们之间以一种插件式的.松耦合的方式连接在一起,模型负责业务 ...
- Java 多线程并发编程一览笔录
Java 多线程并发编程一览笔录 知识体系图: 1.线程是什么? 线程是进程中独立运行的子任务. 2.创建线程的方式 方式一:将类声明为 Thread 的子类.该子类应重写 Thread 类的 run ...
- Erlang OTP设计原则Gen_Fsm行为[转]
转自: http://www.cnblogs.com/yourihua/archive/2012/05/13/2497776.html 1. Fsm 称为 有限状态机,举个例子,游戏中的怪物称为NPC ...
- 关于IOS下日期格式分隔符 - 、 /的问题
之前我们项目有一个低价日历,服务端下发的时间格式为: "2014-07-21 09:45:12" 然后一直出不了数据,后来发现. IOS下无论chrome.safari还是Uc如 ...
- 《算法》C++代码 快速排序
快速排序,简称快排,常称QuickSort.QSort.在排序算法中非常常用,其编程复杂度低,时间复杂度O(NlogN),空间复杂度O(N),执行效率稳定,而且常数很低. 基本思想就是二分,例如你要将 ...