У меня есть содержимое ниже:
NODE_1
port 1
description blah
port 2
description blah blah
NODE_2
port 1
description blah
port 2
description blah
NODE_3
port 1
port 2
NODE_4
port 1
port 2
NODE_5
port 1
port 2
NODE_6
port 1
description blahdy blah
port 2
description floop-a-doop
Я пытаюсь распечатать свойства совпадения первых трех совпадений NODE
awk 'BEGIN{count=0}
match($0,/NODE/,a)
{
if(RSTART != 0){
print "*******************************"
for (i in a)
print i"-->"a[i]
count++;
print "count-->"count;
print "*******************************"
}
if (count >= 3)
{
exit
}
}' awksampledata5.txt
Вывод
NODE_1
*******************************
0start-->1
0length-->4
0-->NODE
count-->1
*******************************
NODE_2
*******************************
0start-->1
0length-->4
0-->NODE
count-->2
*******************************
NODE_3
*******************************
0start-->1
0length-->4
0-->NODE
count-->3
*******************************
Я не хочу, чтобы NODE_1, NODE_2 и NODE_3 печатались.Но я не знаю, как это печатается.
ОТВЕТ РЕДАКТИРОВАННЫЙ КОД:
$ awk 'BEGIN{count=0}
match($0,/NODE/,a){
if(RSTART != 0){ <-- this matters new lines matters.
print "*******************************"
for (i in a)
print i"-->"a[i]
count++;
print "count-->"count;
print "*******************************"
}
if (count >= 3)
{
exit
}
}' awksampledata5.txt
*******************************
0start-->1
0length-->4
0-->NODE
count-->1
*******************************
*******************************
0start-->1
0length-->4
0-->NODE
count-->2
*******************************
*******************************
0start-->1
0length-->4
0-->NODE
count-->3
*******************************