Sed basic and practice
定义:Sed 是针对数据流的非交谈式编辑器,它在命令行下输入编辑命令并指定文件,然后可以在屏幕上看到编辑命令的输出结果。
好处:Sed 在缓冲区内默认逐行处理数据,所以源文件不会被更改和破坏。
格式:Sed ‘command' filename
原理:Sed 用数字或规则表达式在定位编辑的地址,然后Command告诉Sed如何处理该行。可以打印,删除,或者更改。
#/bin/bash
echo 'here is a sed script'
echo '======= print the content of employees'
cat employees
echo '======= delete line1 to 3 and print'
sed '1,3d' employees
#delete line include frank
sed '/frank/d' employees
#delete line unclude frank
sed '/frank/!d' employees
#print frank line and all line
sed '/frank/p' employees
#print frank line only
sed -n '/frank/p' employees
#delete line4 to end and print
sed '4,$d' employees
#delete last ine and print
sed '$d' employees
#delete line including john and print
sed '/john/d' employees
#replace all john to hello
sed 's/john/hello/g' employees
#replace all john to hello and print replaced only
sed -n 's/john/hello/gp' employees
#print replaced line only
sed -n 's/^john/hello/p' employees
#replace nn to nn. and print
sed 's/[0-9][0-9]$/&.5/' employees
#print replaced line only
sed -n 's/[0-9][0-9]$/&.5/p' employees
#print from eric to mark
sed -n '/eric/,/mark/p' employees
#print line1 to mark
sed -n '1,/^mark/p' employees
#delete line and replace
sed -e '1,3d' -e 's/frank/huma/' employees
Sed 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 分) ...
- Grep basic and practice
定义:Grep (Globally search for the reqular expression and print out the line). 好处:Grep 在执行时不需要先调用编辑程序, ...
- 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.例如给定 ...
随机推荐
- POJ-2421-Constructing Roads(最小生成树 普利姆)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26694 Accepted: 11720 Description The ...
- springmvc springboot 跨域问题(CORS)
官方文档:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cors.html springmvc s ...
- Vue 去脚手架
上回模仿了一个nw,按照原理说,简单. 今天说Vue,脚手架是个好东西,做项目都给你配置好,不过对于我这种只想做一个界面的人来说,有点儿太大了,用不上. 如果说,不用脚手架要面临哪些问题呢. 1. 组 ...
- 3155: Preprefix sum
3155: Preprefix sum https://www.lydsy.com/JudgeOnline/problem.php?id=3155 分析: 区间修改,区间查询,线段树就好了. 然后,这 ...
- Python的import导入与时间
一.模块与包 模块,在Python可理解为对应于一个文件.在创建了一个脚本文件后,定义了某些函数和变量.你在其他需要这些功能的文件中,导入这模块,就可重用这些函数和变量.一般用module_name. ...
- shell -- for、while用法
#数字段形式for i in {1..10}do echo $idone #详细列出(字符且项数不多)for File in 1 2 3 4 5do echo $Filedone #对存在的 ...
- 通过修改Host文件解决主机头访问网站的问题
网站打包发布后,一般都是通过IP地址来进行访问,但是这样不方便记忆.如何设置一个简单的域名,然后通过域名来进行访问呢?一个可行的方法就是修改本机的host文件,添加一条映射关系,把这 ...
- [转]Visual Studio 项目类型 GUID 清单
转自:https://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs Complete li ...
- ubuntu下安装redis及在php中使用
一.安装redis sudo apt-get install redis-server 安装完成后,Redis服务器会自动启动,我们可以通过下面的命令行检查一下: # redis-cli > p ...
- 监控memcache服务
监控memcache服务是否正常,模拟用户(web客户端)检测. 使用nc命令加上set/get来模拟检测,以及监控响应时间及命中率. #!/bin/bash #################### ...