shell学习(3)- grep
[kumufengchun@localhost ~]$ cat sed.txt
my cat's name is betty This is your This dog
my dog's name is This frank This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam
[kumufengchun@localhost ~]$ cat sed.txt | grep -i this
This is your This dog
my dog's name is This frank
This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam
[kumufengchun@localhost ~]$ cat sed.txt | grep -v this
my cat's name is betty This is your This dog
my dog's name is This frank This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam
[kumufengchun@localhost ~]$ cat sed.txt | grep -iv this
my cat's name is betty [kumufengchun@localhost ~]$ cat sed.txt | grep -n This
:This is your This dog
:my dog's name is This frank
:This is your fish
:my fish's name is This george
:This is your goat
:my goat's name is This adam
[kumufengchun@localhost ~]$ cat sed.txt | grep -w This
This is your This dog
my dog's name is This frank
This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam
[kumufengchun@localhost ~]$ cat sed.txt | grep -c This [kumufengchun@localhost ~]$ cat sed.txt | grep -o This
This
This
This
This
This
This
This
[kumufengchun@localhost ~]$ cat sed.txt | grep -A frank
my dog's name is This frank This is your fish
[kumufengchun@localhost ~]$ cat sed.txt | grep -B frank This is your This dog
my dog's name is This frank
[kumufengchun@localhost ~]$ cat sed.txt | grep -C frank This is your This dog
my dog's name is This frank This is your fish 或的关系
[kumufengchun@localhost ~]$ cat sed.txt | grep -E "frank|adam"
my dog's name is This frank
my goat's name is This adam
通用类
替换每行的第二个This为小写this
[kumufengchun@localhost ~]$ sed -i 's/This/this/2g' sed.txt
[kumufengchun@localhost ~]$ grep '[[:lower:]]his' sed.txt
This is your this dog
[kumufengchun@localhost ~]$ grep '[[:upper:]]his' sed.txt
This is your this dog
my dog's name is This frank
This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam 在文件后边追加 $hello=
[kumufengchun@localhost ~]$ sed -i '$a\$hello=3' sed.txt
[kumufengchun@localhost ~]$ cat sed.txt
my cat's name is betty This is your this dog
my dog's name is This frank This is your fish
my fish's name is This george
This is your goat
my goat's name is This adam
$hello= [kumufengchun@localhost ~]$ grep "hello[^[:upper:]][[:digit:]]" sed.txt
$hello=
[kumufengchun@localhost ~]$ grep "hello[[:punct:]]" sed.txt
$hello=
[kumufengchun@localhost ~]$ grep "he[[:alnum:]]" sed.txt
$hello=
[kumufengchun@localhost ~]$ grep "hello[[:punct:]]" sed.txt
$hello=
shell学习(3)- grep的更多相关文章
- shell学习笔记
shell学习笔记 .查看/etc/shells,看看有几个可用的Shell . 曾经用过的命令存在.bash_history中,但是~/.bash_history记录的是前一次登录前记录的所有指令, ...
- Shell学习之结合正则表达式与通配符的使用(五)
Shell学习之结合正则表达式与通配符的使用 目录 通配符 正则表达式与通配符 通配符 通配符的使用 正则表达式 正则表达式 正则表达式的使用 通配符 正则表达式与通配符 正则表达式用来在文件中匹配符 ...
- Shell学习之Shell特性(一)
Shell学习之Shell特性 目录 命令和文件自动补齐功能 命令历史记忆功能 history.上下键.!number.!string.!$.!! 别名功能 alias.unalias cp.~use ...
- shell学习笔记汇总
1.shell脚本中函数使用 函数定义在前,调用在后,顺序反了就没有效果了.函数调用为:函数名 参数列表 函数内部通过以下变量访问函数的参数:shell脚本函数中: $0: 这个脚本的名字 $n: 这 ...
- shell 学习笔记2-shell-test
一.字符串测试表达式 前面一篇介绍:什么是shell,shell变量请参考: shell 学习笔记1-什么是shell,shell变量 1.字符串测试表达式参数 字符串需要用""引 ...
- Shell学习笔记 - 正则表达式
一.正则表达式是什么? 正则表达式是用于描述字符排列和匹配模式的一种语法规则.它主要用于字符串的模式分割.匹配.查找及替换操作. 二.正则表达式与通配符 1. 正则表达式 用来在文件中匹配符合条件的字 ...
- shell学习总结之自定义函数
shell学习总结之自定义函数 Myfun (){ echo -n "now i is $i " ! [ "$i" ] && exit ; ec ...
- SHELL学习笔记----IF条件判断,判断条件
SHELL学习笔记----IF条件判断,判断条件 前言: 无论什么编程语言都离不开条件判断.SHELL也不例外. if list then do something here ...
- shell学习指南-阅读笔记
shell学习指南真不是刚开始学习shell应该看得书,虽然其中讲了简单的linux命令,shell语法等,但是每章也有些深入和生僻地方,我想如果我刚学shell看到这样的地方一定会头疼的要死.或许也 ...
- 【转】shell学习笔记(一)——学习目的性、特殊字符、运算符等
1 学习shell的目的性 写之前我们先来搞清楚为什么要学shell,学习要有目的性 shell简单.灵活.高效,特别适合处理一些系统管理方面的小问题 shell可以实现自动化管理,让系统管理员的工作 ...
随机推荐
- 最新版本号MYSQL官网下载地址可是必需要注冊后才干下载
因mysql5.0上运行函数不行,决定安装最新版本号的mysql,在网上找了些绿色版的.安装总报1067错误,网上的各种方法都试了,就是不行.浪费时间不说.郁闷死了,最后决定去官网,官 ...
- codeforces776D
传送门 这题的意思就是原本有一个长度为n的01串,再给出m的长度为n的01串,要求你判定是否可以通过原串与m个串中的某些串xor使得原串到达一个状态.n,m小于1e5. 这题最初我发现不可做,因为这貌 ...
- LightOJ1220 —— 质因数分解
题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria PDF (English) Statistics ...
- SVG-Android开源库——SVG生成Vector资源文件的编辑预览工具
Vector矢量图在Android项目中的应用越来越广泛,但是如果你想用Android Studio自带的工具将SVG图片转化成Vector资源文件却是相当麻烦,首先能支持的SVG规范较少,其次操作流 ...
- 网络抓取功能实现 将获取的结果进行过滤并写入到TXT文档中
下面是自己编写的 网络抓取功能实现 将获取的结果进行过滤并写入到TXT文档中 (以防忘记) 原创哟 import java.io.BufferedReader;import java.io.Buffe ...
- bleve搜索引擎是支持基于field搜索的
Query String Query The query language query allows humans to describe complex queries using a simple ...
- Java丨时间判断谁前谁后
直奔主题: String date_str1 = "2016-06-02 23:03:123"; String date_str2 = "2016-06-03 03:03 ...
- Building Objective-C static libraries with categories(ObjC、all_load、force_load)
https://developer.apple.com/library/mac/qa/qa1490/_index.html 之所以使用该标志,和Objective-C的一个重要特性:类别(cat ...
- Json 不同语言的使用
Javascript: 1.使用eval var parse_json_by_eval = function(str){ return eval('('+str+')'); } var value = ...
- Ubuntu下使用gcc编译c文件,未识别cos,sin
Ubuntu下使用gcc编译c文件,虽然我调用了math.h的头文件,但是未识别cos,sin 报错:( fft.c ) /tmp/ccwXjD8C.o: In function `fft': fft ...