0
我使用SED與N選項三個字符串,他錯過了最後一個字符串。 如果偶數行則一切正常sed多行跳躍行與N選項
示例文本:
this is the first line
this is the second line
this is the third line
sed 'N;s/^.*\(first.*\)\n\(second.*$\)/\1\2/;s/ //g'
我想
thisisthefirstline thisisthesecondline
thethirdline
,但我得到
thisisthefirstline thisisthesecondline
第三行
最後一行不處理, SED跳過此下標
s/ //g
四行沒關係
this is the first line
this is the second line
this is the third line
this is the fourth line
thisisthefirstline**thisisthesecondline**
thisisthethirdline
thisisthefourthline
爲奇數行的並不總是處理最後一排
一個簡單的解決方案 - 使用管道
sed 'N;s/^.*\(first.*\)\n\(second.*$\)/\1\2/' | sed 's/ //g'
,但我會做沒有管