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 和 ...
随机推荐
- R语言学习笔记(一):mode, class, typeof的区别
要了解这三个函数的区别,先了解numeric, double与integer. 在r中浮点数有两个名字叫numeric与double. double是指它的类型(type)名字,numeric是指它的 ...
- Verilog学习笔记基本语法篇(七)········ 生成块
生成块可以动态的生成Verilog代码.可以用于对矢量中的多个位进行重复操作.多个模块的实例引用的重复操作.根据参数确定程序中是否包含某段代码.生成语句可以控制变量的声明.任务和函数的调用.还能对实例 ...
- 12、K最近邻算法(KNN算法)
一.如何创建推荐系统? 找到与用户相似的其他用户,然后把其他用户喜欢的东西推荐给用户.这就是K最近邻算法的分类作用. 二.抽取特征 推荐系统最重要的工作是:将用户的特征抽取出来并转化为度量的数字,然后 ...
- Hibernate-ORM:13.Hibernate中的连接查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客将会解释Hibernate中的连接查询(各种join) 一,目录 1.内链接 1.1显式内连接(inn ...
- Hibernate-ORM:07.Hibernate中的参数绑定
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客会讲解Hibernate中的参数绑定,就是相当于sql语句中的where后面的条件 一,讲解概述: 1 ...
- Myeclipse报错-Java compiler level does not match 完美解决方法
从别的地方导入一个项目的时候,经常会遇到eclipse/Myeclipse报Description Resource Path Location Type Java compiler level d ...
- 纯js生成QRCode
纯js,不依赖jquery,非常好用,废话不多说,直接上代码! <!DOCTYPE html> <html> <head> <meta charset=&qu ...
- python中logging的常用方法
logging常用 # -*- coding:utf-8 -*- __author__ = "lgj" import os import sys import time impor ...
- OpenCV实现SIFT图像拼接源代码
OpenCV实现SIFT和KDtree和RANSAC图像拼接源代码,此源代码由Opencv2.4.13.6和VC++实现,代码本人已经调试过,完美运行,效果如附图.Opencv2.4.13.6下载地址 ...
- NO8——排序
//sort #include<algorithm> bool cmp(const int a,const int b) { return a>b;//降序排列 } //qsort ...