2016-10-10 4 views
0

두 개의 정규 표현식 사이에 파일의 인쇄 부분을 인쇄하려고합니다. 첫 번째 표현식은 패턴 1, Error: 또는 패턴 2 FAILED 일 수 있으며 마지막 표현식은 고정 패턴 (----------)이 될 수 있습니다. 파일의 섹션의여러 패턴 일치

예 : 내가 얻을 관리했습니다 무엇

Line 01 

10-10-16 22:23:34 Error: Failed to update discount row [Customer ABC|£-336.95] 
10-10-16 22:23:34 Error processing file information, Block 27. 
---------------------------------------------------------------------- 
Line 05 

Line 06 

Line 07 

10-10-16 22:26:52 Error: Failed to update discount row [Customer DEF|£-0.66] 
10-10-16 22:26:52 Error processing file information, Block 37. 
---------------------------------------------------------------------- 
Line 11 

Line 12 

Line 13 

20161010 22:28:25 File 6 FAILED... FILE11.txt 
---------------------------------------------------------------------- 
Line 16 

Line 17 

Line 18 

10-10-16 22:31:30 Error: Failed to update discount row [Customer JKL|£-155.88] 
10-10-16 22:31:30 Error processing file information, Block 3. 
---------------------------------------------------------------------- 
Line 22 

Line 23 

Line 24 

10-10-16 22:33:04 Error: Failed to update discount row [Customer MNO|£-12.65] 
10-10-16 22:33:04 Error processing file information, Block 9. 
Line 27 

Line 28 

Line 29 

20161010 22:35:41 File 7 FAILED... FILE12.txt 
---------------------------------------------------------------------- 

The output I'm looking for is below 

10-10-16 22:23:34 Error: Failed to update discount row [Customer ABC|£-336.95] 
10-10-16 22:23:34 Error processing file information, Block 27. 
---------------------------------------------------------------------- 
10-10-16 22:26:52 Error: Failed to update discount row [Customer DEF|£-0.66] 
10-10-16 22:26:52 Error processing file information, Block 37. 
20161010 22:28:25 File 6 FAILED... FILE11.txt 
---------------------------------------------------------------------- 

10-10-16 22:31:30 Error: Failed to update discount row [Customer JKL|£-155.88] 
10-10-16 22:31:30 Error processing file information, Block 3. 
---------------------------------------------------------------------- 
10-10-16 22:33:04 Error: Failed to update discount row [Customer MNO|£-12.65] 
10-10-16 22:33:04 Error processing file information, Block 9. 
20161010 22:35:41 File 7 FAILED... FILE12.txt 
---------------------------------------------------------------------- 

은 하나 또는 다른이 명령을 사용하여 :

cat FILE* | sed -n '/Error/,/------/p' >> ${TEMP}/err.tmp 

cat FILE* | sed -n '/FAILED/,/------/p' >> ${TEMP}/err.tmp 

을하지만 내 출력은 텍스트가 나타납니다 순서가 아닌 파일 :

10-10-16 22:23:34 Error: Failed to update discount row [Customer ABC|£-336.95] 
10-10-16 22:23:34 Error processing file information, Block 27. 
---------------------------------------------------------------------- 
10-10-16 22:26:52 Error: Failed to update discount row [Customer DEF|£-0.66] 
10-10-16 22:26:52 Error processing file information, Block 37. 
---------------------------------------------------------------------- 
10-10-16 22:31:30 Error: Failed to update discount row [Customer JKL|£-155.88] 
10-10-16 22:31:30 Error processing file information, Block 3. 
---------------------------------------------------------------------- 
10-10-16 22:33:04 Error: Failed to update discount row [Customer MNO|£-12.65] 
10-10-16 22:33:04 Error processing file information, Block 9. 
---------------------------------------------------------------------- 
20161010 22:28:25 File 6 FAILED... FILE11.txt 
---------------------------------------------------------------------- 
20161010 22:35:41 File 7 FAILED... FILE12.txt 
---------------------------------------------------------------------- 

온라인 솔루션 검색 중 하나를 찾을 수 없습니다.

답변

0

awk the rescue!

$ awk '/Error/||/Failed/,/----/' file 
+0

완벽합니다. 정확히 내가 무엇을 찾고 있었는지. 시원한. 고맙습니다. –