歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Sed的使用方法

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 --不打印輸出結果. -->
Copyright © Linux教程網 All Rights Reserved