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
----------------------------------------------------------------------
任何幫助將不勝感激,因爲我一直在尋找一個解決方案和一直沒有找到。
完美。正是我在找什麼。涼。謝謝。 –