sed高階程式設計(一)

2021-07-09 18:49:10 字數 1204 閱讀 8117

d:刪除多行組中的單隔行。

p:列印多行組中的單隔行。

next命令,小寫n命令使sed移動到資料流中文字的下一行。

$cat data

the first meeting of the linux system

administrator's group will be held on tuesday.

all system adminstrators should attend this meeting .

thank you for your attendance

$sed '

> n

> s/system administrator/desktop users/

> ' data

the first meeting of the linux system administrator'

s group will be held on tuesday.

all system administrator should attend this meeting.

thank you for your attendance.

#通過使用n命令將下一行合併到找到第乙個單詞的行,可以探測到跨行的短語。(問題:到達資料流最後一行,n命令不能找到匹配的資料。)

this is

the header line.

this is

thefirst data line.

this is

thesecond data line.

this is

thelast line.

$sed -n '/first/ ' data2

this is

thefirst data line.

this is

thesecond data line.

this is

thefirst data line.

#(1)當包含單詞first的行出現時,h命令將行放到保留空間中。

(2)p命令列印模式空間的內容,即仍然是第一行資料。

(3)n命令檢索資料流中的下一行,將其放到模式空間。

(4)p命令列印模式空間的內容,第二行資料。

(5)g命令將保留空間的內容(第一行資料)放回到模式空間,替換當前文字。

(6)p命令列印模式空間的內容,它現在回到第一行資料。

《shell高階程式設計》 sed的使用

sed基本用法 sed的常用命令 sed的條件工具 root svr5 sed n p a.txt 輸出所有行,等同於cat a.txt root svr5 sed n 4p a.txt 輸出第4行 root svr5 sed n 4,7p a.txt 輸出第4 7行 root svr5 sed n...

sed高階用法

echo mmj evan df sed s 2 g 表示式含義s 表示替換命令 表示第乙個引號前的內容 表示兩引號之間的內容 表示引號後的內容 2表示第二對括號裡面的內容 輸出結果 evan同理 echo mmj evan df sed s 1 g 輸出結果為 mmj批量修改 echo excut...

sed高階指令

n命令簡單來說就是提前讀取下一行,覆蓋模型空間前一行,然後執行後續命令。然後再讀取新行,對新讀取的內容重頭執行sed 從test檔案中取出偶數行 root localhost cat test this is 1 this is 2 this is 3 this is 4 this is 5 roo...