2017-06-22 53 views
-1

output.txt的(原創劇本之前) 蘋果移動 電話關於Bash/Shell腳本:如何(添加文本)而不是(刪除)輸出文件中的所有文本?

input.txt

Samsung Gallaxy 
Tablet 
Samsung S7 mobile 
Telephone 
Oneplus3 mobile 
Telephone 

我使用這個命令: sed -n -e '/mobile/,/Telephone/ p' input.txt > output.txt

output.txt的

Samsung S7 mobile 
Telephone 
Oneplus3 mobile 
Telephone 
Apple mobile 
Telephone 

結果幾乎是完美的.. 但我需要的4線在output.txt結束,沒有它刪除

> Apple mobile 
> Telephone 

請幫助:(

+1

你的意思是追加? '>>'而不是'>'? – archemiro

回答

1

awk也將實現你的目標,

​​

Bri EF解釋,

  • /Telephone|mobile/:搜索行包含Telephonemobile,然後打印出來。
+0

它仍然替換輸出文件中的所有現有內容:( –

+0

@ChristianJensen,你可以在問題中顯示你的預期輸出嗎? – CWLiu

+0

是是是!!!! –

0

使用grep

grep -E "(Telephone|mobile)" filename >>outputfilename 
相關問題