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可以实现自动化管理,让系统管理员的工作 ...
随机推荐
- Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file...
Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: 把tomcat中的日志删除, ...
- ABAP OLE常用方法和属性
转自 http://www.cnblogs.com/eric0701/p/5213694.htmlSAP EXCEL OLE常用方法和属性 附加网上找到的比较好的源代码示例一份 1.ole中如何保存和 ...
- HDU3065 病毒侵袭持续中 —— AC自动机
题目链接:https://vjudge.net/problem/HDU-3065 病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 从数据的角度带你深入了解IPFS
IPFS 和区块链有着非常紧密的联系, 随着区块链的不断发展,对数据的存储需求也越来越高.本文从IPFS 的底层设计出发, 结合源代码, 分析了IPFS 的一些技术细节. 一.概述 IPFS 和区块链 ...
- macbook清理磁盘空间
前言:作为一名程序员,使用MacBook时间久了之后难免都会遇到“磁盘空间不足”的警告,这时就可以清理如下文件夹,一般就可以清理出几十个G的大小! 1.删除“~/资源库/Developer/Xcode ...
- 限制远程桌面登录IP的方法
转自:http://www.cnblogs.com/vaexi/articles/2106623.html 限制远程桌面登录IP的方法 第一种方法: 1.打开Windows自带的防火墙2.开放允许例外 ...
- 支持源码单步调试QT库编译笔记
支持源码单步调试QT库编译笔记 编译环境:windows 10 编译工具:mingw_4_4_0 Qt源码版本:qt-everywhere-opensource-src-4.8.5(下载地址:http ...
- c++11 右值引用和移动语义
什么是左值.右值 最常见的误解: 等号左边的就是左值,等号右边的就是右值 左值和右值都是针对表达式而言的, 左值是指表达式结束后依然存在的持久对象 右值是指表达式结束时就不再存在的临时对象区分: 能对 ...
- C语言之fileno()函数--获取已经打开的文件的文件描述符(小技巧)
open函数相关的: /* open 是系统调用 返回的是文件句柄*/ #include <sys/stat.h> #include <fcntl.h> int open(c ...
- HDU 1394 树状数组+离散化求逆序数
对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们 ...