Sed 的使用方法
来源:互联网 发布:巨人网络策划笔试题 编辑:程序博客网 时间:2024/04/30 11:04
1>.Sed 读取数据
sed
A).使用sed
从一行开始查找一直到出现有某个词语的行结束
The honesuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendanc.
-->
//从第二行 到出现The的行
sed -n '2,/The/'p test.txt
B). 匹对字符
查找一个含有 $的字符的行
sed -n '/\$/'p test.txt
The honesuckle band played all night long for only $90.
-->
sed -n '/The/'p test.txt
The honesuckle band played all night long for only $90.
The local nurse Miss P.Neave was in attendanc.
-->
C).整篇显示
sed -n '1,$p' test.txt
D).任何单词的行
sed -n '/.*ing/'p test.txt
E).显示行号
sed -n -e '/music/=' test.txt
如果既显示行号又显示该行的内容可以使用
sed -n -e '/music/p' -e '/music/=' test.txt
F). 第一行与最后一行的显示
# the first line
sed -n '1p' test.txt
# and the last line
sed -n '$p' test.txt
2>.sed 的 添加字符和文件
3>.sed的替换与删除
The honesuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendanc.
-->
A).首字符的删除
#删除每行开始的T字母
sed 's/^T*//g' test.txt
#把经过输出到一个新的文件test1.txt中
sed 's/^T*//gw test1.txt' test.txt
w --文件名 将结果输出定向到一个文件
p --缺省情况下将被替换行写入标准输出,
n --不打印输出结果.
-->
sed
A).使用sed
从一行开始查找一直到出现有某个词语的行结束
The honesuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendanc.
-->
//从第二行 到出现The的行
sed -n '2,/The/'p test.txt
B). 匹对字符
查找一个含有 $的字符的行
sed -n '/\$/'p test.txt
The honesuckle band played all night long for only $90.
-->
sed -n '/The/'p test.txt
The honesuckle band played all night long for only $90.
The local nurse Miss P.Neave was in attendanc.
-->
C).整篇显示
sed -n '1,$p' test.txt
D).任何单词的行
sed -n '/.*ing/'p test.txt
E).显示行号
sed -n -e '/music/=' test.txt
如果既显示行号又显示该行的内容可以使用
sed -n -e '/music/p' -e '/music/=' test.txt
F). 第一行与最后一行的显示
# the first line
sed -n '1p' test.txt
# and the last line
sed -n '$p' test.txt
2>.sed 的 添加字符和文件
3>.sed的替换与删除
The honesuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:10.
The local nurse Miss P.Neave was in attendanc.
-->
A).首字符的删除
#删除每行开始的T字母
sed 's/^T*//g' test.txt
#把经过输出到一个新的文件test1.txt中
sed 's/^T*//gw test1.txt' test.txt
w --文件名 将结果输出定向到一个文件
p --缺省情况下将被替换行写入标准输出,
n --不打印输出结果.
-->
- Sed 的使用方法
- Sed的使用方法
- Sed 的使用方法
- sed的基本使用方法
- sed使用方法
- sed使用方法
- sed使用方法
- sed&awk基本使用方法
- sed&awk基本使用方法
- linux sed命令使用方法
- sed&awk基本使用方法
- shell: sed使用方法
- sed 详细使用方法
- sed&awk基本使用方法
- sed 工具基本使用方法
- sed的精华贴
- sed的神奇
- sed的使用
- javascript setTimeout方法的使用
- cocos2d-x 编译 Anroid版本遇到的问题以及解决办法
- 固体模拟简介(Introduction to solid)
- shell的一些问题
- 数据库日志减肥。自己试过可以
- Sed 的使用方法
- ORA-12519引出的问题
- Windows Server 2008 R2 下配置证书服务器和HTTPS方式访问网站
- Keepalived安装
- ssh 登录基本原理和验证过程
- iframe跨域
- 寻找一个字符串中最长的重复子串,如 abcdabc 最长重复串 是abc
- Opencv MeanShif 代码分析
- zoj 3468