Good day. Tell me how you can correctly add the prefix to a certain number of lines. There is a file containing ~ 100k lines. With the structure of the form:
AAA:BBB:CCC AAA:BBB:CCC AAA:BBB:CCC $$ AAA:BBB:CCC AAA:BBB:CCC AAA:BBB:CCC $$ AAA:BBB:CCC AAA:BBB:CCC AAA:BBB:CCC $$ AAA:BBB:CCC AAA:BBB:CCC AAA:BBB:CCC I need to add the first 3 lines to the prefix 001: from 3 to 6, for example 007: from 6 to 9 :010 To get a file with the structure:
001:AAA:BBB:CCC 001:AAA:BBB:CCC 001:AAA:BBB:CCC $$ 007:AAA:BBB:CCC 007:AAA:BBB:CCC 007:AAA:BBB:CCC $$ 010:AAA:BBB:CCC 010:AAA:BBB:CCC 010:AAA:BBB:CCC For one line I use approximately the following code:
while(<IN>) { if ($. % 3 == 1){ my $line = $_; print OUT "002:".$line; } } close IN; close OUT; How does it scale to use the counter? Maybe there is a possibility in Perl to specify the gap?
$$. while meeting$$you need to switch the current number to the next one. - Mike$$change the number and do nothing else. Otherwise (the string is not equal to$$) type the current number and string. If you do this by line numbers ... well, ok. but you still need to do the same thing just to check that the remainder of the division by 4 is not equal to any particular value, but it seems to me less convenient - Mike