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 和 ...
随机推荐
- P2678 跳石头(二分答案)
P2678 跳石头 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间 ...
- 人工智能,图片识别,与GUI编程
GUI编程: https://sourceforge.net/projects/pyqt/ 百度aip图片识别 https://pypi.python.org/pypi/baidu-aip
- jmeter插件之jsonpath提取响应结果和做断言
准备工作: 1. jmeter3.X已经自带了提取响应结果的插件:JSON Extractor 2. 下载断言插件:https://jmeter-plugins.org/wiki/JSONPathAs ...
- 近期准备发布我的asp.net框架
此框架为超轻量级架构,适合做中小型的b/s项目
- ExtJs4.1目录结构介绍和使用说明[转]
一.在做ExtJs开发之前首先要到网站上下载ExtJs的开发包,我用的最新版本是4.1.1.此版本相对于之前的版本目录结构发生了一些变化,没有了adapter目录, 目录结构如下 文件/文件夹名的作用 ...
- log报错: Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
报错: 解决方式: 1.登录数据库查看错误原因 结果发现账号无法正常登录出现账号被锁定的错误. 2.如何账号解锁? 用sys系统管理员账号登录数据库 SQL> alter user 用户名 ac ...
- Qt 在Label上面绘制罗盘
自己写的一个小小的电子罗盘的一个小程序,不过是项目的一部分,只可以贴绘制部分代码 效果如下图 首先开始自己写的时候,虽然知道Qt 的坐标系是从左上角开始的,所以,使用了算法,在绘制后,在移动回来,但是 ...
- Django学习笔记(一):环境安装与简单实例
Django学习笔记(一):环境安装与简单实例 通过本文章实现: Django在Windows中的环境安装 Django项目的建立并编写简单的网页,显示欢迎语与当前时间 一.环境安装 结合版本兼容性等 ...
- SQL 语句中 exists和not exists的用法
exists (sql 返回结果集,为真) not exists (sql 不返回结果集,为真) 如下: 表A ID NAME ...
- 基于HTML5移动web应用
一.基于HTML5移动web应用 1.canvas 绘图 2.多媒体 3.本地存储 4.离线应用 5.使用地理位置 6.移动web框架 二.具体说明 1.HTML5标准最大的变化就是支持Web绘图 ...