0

I want to copy a content of a file starting from word (searched word/line) to the end of the file.

Example: File1:

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.

I want to copy contents to file2 from line that has "CT" till the end of the file. Output : 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.
4

2 回答 2

3

您可以使用sed

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

awk

awk '/searchtext/ {flag=1} flag;' file1 > file2
于 2012-08-29T21:53:02.007 回答
1
awk '{if($0~/CT/)p=1;if(p)print}' your_file
于 2012-08-30T05:58:15.493 回答