對於這樣的文本文件之間的字符串出現次數:具有至少2 TAG1和4總線計數兩個圖案
START_PATTERN
...TAG1...
...TAG2...
...TAG3...
...TAG4...
STOP_PATTERN
START_PATTERN
...TAG1...
...TAG5...
...TAG4...
...TAG1...
STOP_PATTERN
我想回到第一塊(開始和結束之間)。 所以結果在這種情況下,簡直是:
START_PATTERN
...TAG1...
...TAG5...
...TAG4...
...TAG1...
STOP_PATTERN
我已經試過這樣:
awk 'x {next}
/START_PATTERN/
{n=1;f=1;count=0}f {lines[n++]=$0}
/END_PATTERN/
{if(n==4){/TAG1/count++;x=1}} #the message should appear for 9 lines
{print count}' file
謝謝!
是的,這就是我一直在尋找的!謝謝! –