定义:Grep (Globally search for the reqular expression and print out the line).

好处:Grep 在执行时不需要先调用编辑程序,同时不需要以“//” 来括起规则表达式,所以比vi等快很多。

格式:grep pattern filename1 filename2 .....

术语:pattern, 字符串样式,多被单引号‘ ’包围。

原理:Grep 在文件里查找规则表达式,并打印包含该表达式的所有行。

Practice script

#/bin/bash
echo 'here is a grep script'
echo '======= print the content of employees'
cat employees
#search line including eric
grep eric employees echo '======= grep option practice'
#show line and line number
grep -n '^er' employees
#print bash return, ,,
echo $?
#print line number only
grep -c '^er' employees
#print filename only
grep -l '^er' employees awkfile
#display matching word file and line
grep -w tokoyo employees awkfile
#ignore capital
grep -i tOKoyo employees awkfile
#print unmatch line
grep -v tokoyo employees
#mark module number
grep -b tokoyo employees
#print error only
grep -s tokoyo employees #regular expression practice
echo '======= regular expression practice'
grep frank emp*
grep '^green' employees
grep '12$' employees
grep '939..' employees
grep '^[ej]' employees
grep '^j..[nk]' employees
grep '\<mar.*' employees
grep '\<mar.*12' employees
grep -vin 'ic' employees
grep -l 'ic' employe*

Output of the script

# ./grep.sh
here is a grep script
======= print the content of employees
eric beijing
john xian
mark henan
frank tokoyo
green england
eric beijing
======= grep option practice
:eric beijing employees
employees:frank tokoyo
employees:frank tokoyo
eric beijing
john xian
mark henan
green england
:frank tokoyo
frank tokoyo
======= regular expression practice
frank tokoyo
green england
mark henan
mark henan
eric beijing
john xian
john xian
mark henan
mark henan
:john xian
:mark henan
:frank tokoyo
:green england
employees

q

最新文章

  1. 【Windows】为节省系统资源,停掉不必要的服务
  2. 问题解决——OpenGL超级宝典 第四章 4.5.2 关于freeglut.lib问题的解决过程
  3. swt byte[] 与 Image的转换
  4. 在Eclipse中使用Propertites Editor插件来解决property文件中文显示乱码
  5. Filter设计实现IP地址限制
  6. 3G 2G GPRS 1G的概念
  7. shell 二元操作符 =~
  8. Android中的多媒体显示之图片缩放
  9. linux 内核开发基础
  10. 使用EXCEL设置“下拉菜单”选项功能
  11. bigdata_ambari修改hiveserver_metastore链接库(从0.14 升级到1.2.1 )
  12. MacOSX 中如何动态隐藏Dock Icon
  13. [C++学习历程]中级部分 OpenGL第一个例子实现
  14. ROS_Kinetic_08 ROS的集成开发环境(IDEs)之使用Eclipse
  15. Clloection接口 与List接口
  16. Python判断相等
  17. ltp-ddt nor_mtd_dd_rw_jffs2
  18. 左耳听风-ARTS-第2周(2019/3/31-2019/4/6)
  19. 浅谈HTTP和HTTPS的区别
  20. 华硕FX503V 安装ubuntu遇到问题解决

热门文章

  1. 学习RUNOOB.COM进度二
  2. SHIFT(文字列の指定位置数の移動)
  3. python2.7练习小例子(十八)
  4. Android当代码方法超过65536个时,在2.3机器上会不能安装,出现INSTALL_FAILED_DEXOPT错误
  5. NOI中“大整数加法”问题不能AC的解决建议
  6. cut 与 awk
  7. BZOJ 1010 HNOI2008 玩具装箱 斜率优化
  8. AtomicIntegerFieldUpdater使用
  9. 如何创建LocalDB数据库和数据库实例
  10. web相关基础知识3