2012-08-29 3 views
0

단어 (검색 한 단어/줄)부터 파일의 끝까지 파일의 내용을 복사하고 싶습니다.정규식 단어에서 파일 끝까지 복사하는 내용을 복사하십시오.

예 : 을 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. 

내가 파일의 마지막까지 "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. 
+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

관련 문제