lundi 21 mars 2022

Numbering lines in sections of file with repeating pattern

I am trying to use awk to number repeated lines with the pattern scan-hgi-oi.[0-9][0-9][0-9].out4 in a larger file

The closed I have got to success is the following command

awk *'BEGIN{i=0}{if ($1="scan-hgi-oi.[0-9][0-9][0-9].out4") { i=i+1}   printf"%i\n","%f",i,$1}' test2 > test3*

This only seems to substitute every line with the number 0

The reason why I would like to use awk and not sed for this problem is that the number of repetitions of the pattern is different in each section.

The file has sections looking as follows:

xxxxxxx\
yyyyyyy\
zzzzzz\
scan-hgi-oi.001.out4 number\
scan-hgi-oi.001.out4 number\
scan-hgi-oi.001.out4 number\
ppppppp
xxxxxx\
yyyyyyy\
zzzzzzz\
scan-hgi-oi.002.out4 number\
scan-hgi-oi.002.out4 number\
scan-hgi-oi.002.out4 number\
scan-hgi-oi.002.out4 number\
ppppppp

I would like to get the result beneath.

xxxxxx\
yyyyyyy\
zzzzzzz\
1 number\
2 number\
3 number\
ppppppp
xxxxxx\
yyyyyyy\
zzzzzzz\
1 number\
2 number\
3 number\
4 number\
ppppppp

Hope you can help.

With kind regards from Svend

Aucun commentaire:

Enregistrer un commentaire