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
随机推荐
- MySQL单表查询语句练习题
/*1. 查询出部门编号为30的所有员工*/ /* 分析: 1). 列:没有说明要查询的列,所以查询所有列 2). 表:只一张表,emp 3). 条件:部门编号为30,即deptno=30 */ ; ...
- sqlsever存储过程学习笔记
1,创建数据表 use test create table money( id ,) primary key, money int, monetary_unity char ); 2,考虑到货币单位的 ...
- 剑指Offer - 九度1386 - 旋转数组的最小数字
剑指Offer - 九度1386 - 旋转数组的最小数字2013-11-24 01:57 题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转 ...
- 《Cracking the Coding Interview》——第1章:数组和字符串——题目1
2014-03-18 01:25 题目:给定一个字符串,判断其中是否有重复字母. 解法:对于可能有n种字符的字符集,用一个长度为n的数组统计每个字符的出现次数,大于1则表示有重复. 代码: // 1. ...
- js实现类bootstrap模态框动画
在pc端开发,模态框是一个很常用的插件,之前一直用的第三方插件,比如bootstrap,jQuery的模态框插件,最近还用了elementUI的.但是会发现其实动画效果都差不多,那么如何去实现这样一个 ...
- Python 字符串格式化输出方式
字符串格式化有两种方式:百分号方式.format方式. 其中,百分号方式比较老,而format方式是比较先进的,企图替代古老的方式,目前两者共存. 1.百分号方式 格式:%[(name)][flags ...
- HTML5 FileReader接口学习笔记
1.FileReader概述 FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据. 其中F ...
- winform对图片进行灰度处理
//图片进行灰度处理 //originalImage为原图像 返回灰度图像 private Bitmap GrayImage(Bitmap originalImage) { ImageAttribut ...
- 易语言.开源(绝地求生多功能盒子)类似LOL盒子
下载地址:https://pan.baidu.com/s/1OXwCjGJODkcZVrCwVixu3Q 成品地址:https://pan.lanzou.com/i0rmdwj
- hnust 档案管理
问题 E: 档案管理 时间限制: 1 Sec 内存限制: 128 MB提交: 274 解决: 105[提交][状态][讨论版] 题目描述 X老师管理着学校的档案室,经常会有其他的老师来档案室存文件 ...