将文件内容从正则表达式字词复制到文件末尾

时间:2012-08-29 21:38:21

标签: linux file bash shell copy

我想复制从word(搜索的字/行)开始到文件末尾的文件内容。

实施例: 文件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,直到文件末尾。 输出: file2的

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.

2 个答案:

答案 0 :(得分:3)

您可以使用sed

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

awk

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

答案 1 :(得分:1)

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