Grep basic and practice
定义: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
Grep basic and practice的更多相关文章
- PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642
PAT (Basic Level) Practice (中文)1078 字符串压缩与解压 (20 分) 凌宸1642 题目描述: 文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一 ...
- PAT (Basic Level) Practice (中文)1070 结绳 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文)1070 结绳 (25 分) 凌宸1642 题目描述 给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下 ...
- PAT (Basic Level) Practice (中文)1065 单身狗 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文)1065 单身狗 (25 分) 凌宸1642 题目描述: "单身狗"是中文对于单身人士的一种爱称.本题请你从上万人的大 ...
- PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文)1055 集体照 (25 分) 凌宸1642 题目描述: 拍集体照时队形很重要,这里对给定的 N 个人 K 排的队形设计排队规则如下: 每 ...
- PAT (Basic Level) Practice (中文)1054 求平均值 (20 分) 凌宸1642
PAT (Basic Level) Practice (中文)1054 求平均值 (20 分) 题目描述 本题的基本要求非常简单:给定 N 个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的 ...
- PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 凌宸1642
PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) 目录 PAT (Basic Level) Practice (中文) 1050 螺旋矩阵 (25 分) ...
- Awk basic and practice
定义:Awk是一种程序语言,用来处理数据和产生报告.数据可来自标准输入,文件,管道输出. 格式:#awk '/pattern/ {action}' filename 术语:pattern, 样式是由正 ...
- PAT (Basic Level) Practice (中文)1057 数零壹 (20 分) (按行输入带空格的字符串)
给定一串长度不超过 1 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有多少 0.多少 1.例如给定 ...
- PAT (Basic Level) Practice (中文)1022 D进制的A+B
1022 D进制的A+B 输入两个非负 10 进制整数 A 和 B (≤2^30^−1),输出 A+B 的 D (1<D≤10)进制数. 输入格式: 输入在一行中依次给出 3 个整数 A.B 和 ...
随机推荐
- 深入了解jQuery Mobile-1
介绍 jQuery Mobile是一种触控优化的HTML5 UI框架,旨在制作可在所有智能手机,平板电脑和台式机设备上访问的响应式网站和应用程序 移动页面结构 jQuery Mobile站点必须以HT ...
- (数据科学学习手札02)Python与R在循环语句与条件语句上的异同
循环是任何一种编程语言的基本设置,是进行批量操作的基础,而条件语句是进行分支运算的基础,Python与R有着各自不同的循环语句与条件语句语法,也存在着一些相同的地方. Python 1.for循环 ' ...
- [Cracking the Coding Interview] 4.5 Validate BST
Implement a function to check if a binary tree is a binary search tree. 这道题很经典,让我们判断一棵树是不是二叉查找树.但是首先 ...
- javascript-es6学习笔记
es6技术培训文档 第一阶段:1.let与const用法2.变量的解构赋值3.字符串的扩展4.正则的扩展5.数组的扩展6.函数的扩展7.对象的扩展8.Symbol9.Set和Map数据结构 第二阶段: ...
- 今天买了个pro,开始ios开发
今天买了个mac pro 开始ios开发啦,爽!
- Python中该使用%还是format来格式化字符串?
%还是format 1.皇城PK Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是fo ...
- Python简要标准库(3)
shelve 若只需要一个简单的存储方案,那么shelve模块可以满足你大部分的需要,你所需要的只是为它提供文件名.shelve中唯一有趣的函数是open,在调用的时候他会返回一个Shelf对象 注意 ...
- 学习bash——管道命令
摘要:管道命令概述.常见管道命令的使用(cut/grep.sort/wc/uniq.tee.tr/col/join/paste/expand.xargs.减号-) 一.概述 命令执行完会在屏幕上打印相 ...
- Daily Scrum02 12.01
今天是2013年12月的第一天,希望大家都有一个新的开始,一起努力! Member Today's Task Tomorrow's Task 李孟 Task 856: 熟悉单元测试方法熟悉单元 ...
- [译]如何撤销git仓库里的所有修改?
原文来源:https://stackoverflow.com/questions/29007821/git-checkout-all-the-files 问: 如何撤销我在我git仓库所做的所有修改? ...