2012-08-29 24 views
0

我想複製從文件(搜索到的文字/行)開始的文件內容到文件末尾。複製從正則表達式文件開始到文件結尾的文件內容

舉例: 文件1:

this is a sample text for file1 in PA 
this is a sample text for file1 in CA 
this is a sample text for file1 in CT 
this is a sample text for file1 in IL 
this is a sample text for file1 in MI 
end of the file. 

我要複製的內容從具有「CT」,直到文件的最後一行到file2。 輸出: 文件2

this is a sample text for file1 in CT 
this is a sample text for file1 in IL 
this is a sample text for file1 in MI 
end of the file. 
+0

如果我有在這裏我想從兩個內容的場景文件並將其複製到一個輸出文件? – phani

回答

3

您可以使用sed

sed -n '/searchtext/,$p' file1 > file2 

awk

awk '/searchtext/ {flag=1} flag;' file1 > file2 
+0

謝謝,我會測試一下。 – phani

+0

謝謝,它工作。 – phani

1
awk '{if($0~/CT/)p=1;if(p)print}' your_file 
+0

感謝您花時間和建議的代碼。 – phani

相關問題