Sed 的使用方法

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 --不打印输出结果.
-->
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值