1>.Sed 读取数据sedA).使用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.txtB). 匹对字符查找一个含有 $的字符的行sed -n '/\$/'p test.txtThe honesuckle band played all night long for only $90.-->sed -n '/The/'p test.txtThe honesuckle band played all night long for only $90.The local nurse Miss P.Neave was in attendanc.-->C).整篇显示sed -n '1,$p' test.txtD).任何单词的行sed -n '/.*ing/'p test.txtE).显示行号sed -n -e '/music/=' test.txt如果既显示行号又显示该行的内容可以使用sed -n -e '/music/p' -e '/music/=' test.txtF). 第一行与最后一行的显示# the first linesed -n '1p' test.txt# and the last linesed -n '$p' test.txt2>.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.txtw --文件名 将结果输出定向到一个文件p --缺省情况下将被替换行写入标准输出,n --不打印输出结果.-->
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/394619,如需转载请自行联系原作者