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可以实现自动化管理,让系统管理员的工作 ...
随机推荐
- TMS320C6478+MCP2515
调一个驱动,将看过的资料记录下来. 这个驱动写得比较直观:http://www.51hei.com/bbs/dpj-114085-1.html
- dialog更新数据
将数据显示在最上面
- [Vim 使用]vim 自动括号补全配置
打开Vim的配置文件,windows 上面的配置文件在vim 的安装目录下,_vimrc,使用记事本或vim打开 在下方加入如下代码 inoremap ( ()<ESC>i inorema ...
- ansible 魔法变量
hostvars 可以让你调用其他host的变量和facts, 即使你没有在这个机器上执行过playbook, 你仍然可以访问变量, 但是不能访问facts. 例如: {{ hostvars['te ...
- WebRTC GitHub repo developer's guide
WebRTC GitHub repo developer's guide https://github.com/LingyuCoder/SkyRTC-demo WebRTC GitHub repo ...
- python 复制文件流程
例子代码: [root@master script]# vim copy_file.py #!/usr/bin/python # -*- coding:utf-8 -*- old_file_name ...
- react之redux增加删除数字
比如在页面中添加和删除‘222’ action.js export const ADD= 'ADD'; export const RED='RED'; export const add=(str)=& ...
- Mutual information and Normalized Mutual information 互信息和标准化互信息
实验室最近用到nmi( Normalized Mutual information )评价聚类效果,在网上找了一下这个算法的实现,发现满意的不多. 浙江大学蔡登教授有一个,http://www.zju ...
- POJ3261(后缀数组+2分枚举)
Milk Patterns Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12972 Accepted: 5769 Ca ...
- PHP程序中的redis一些写法
<?php /** * 以下均要先链接好redis */ sdk\libs\RedisHelper::connect("s1")->keys('*'); //这个是获取 ...