博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sed 的使用方法
阅读量:7096 次
发布时间:2019-06-28

本文共 1267 字,大约阅读时间需要 4 分钟。

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 --不打印输出结果.

-->

本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/394619,如需转载请自行联系原作者

你可能感兴趣的文章
ssh互信失败
查看>>
[网络通信]使用fork的TCP通信服务端重起bind问题
查看>>
使用Maven创建的springmvc工程发布到tomcat
查看>>
探测网站(二)httprint探测Web服务器类型
查看>>
使用第三方yum源安装更多rpm软件包
查看>>
struts2 跳转至404 页面的解决方案
查看>>
ThinkPHP 学习笔记2-创建许愿墙2
查看>>
Qt学习之路_14(简易音乐播放器)
查看>>
启动apk的常用方法
查看>>
Mybatis整合Spring
查看>>
iframe多层嵌套时获取元素总结
查看>>
Sql开发技巧
查看>>
Flink教程(三)——基本API定义
查看>>
JQuery、JSON、Ajax在与ervlet结合的工资计算模块
查看>>
SQL操作全集 .
查看>>
如何处理Tomcat日志catalina.out日志文件过大的问题
查看>>
二维数组的简单运用
查看>>
关于魅族note无法连接mac调试
查看>>
6个提升 SQL Select 性能的方法
查看>>
android应用图片加载与存放目录分析
查看>>