Print specific lines of a repeated set of data

I have a file that needs 1st line, 2nd line, and 26th line printed from every chunk of data. Each chunk of data contains 26 lines (#line+%line+24 data lines = 26 lines of data repeated).

Input file:

# This is a data file used for blockA (chunk 1).
% 10576 A 10 0 1
04 (data1)
03 (data2)
F2 (data3)
8B (data4)
.... (data xyz)
CF (data 24)
# This is a data file used for blockA (chunk 2).
% 10576 B 20 1 2
FF
FE
FD
FC
..
AA
# This is a data file used for blockA (chunk 3).
% 10576 C 30 2 3
11
22
33
44
..
7F

Output file should look like this, where lines 1, lines 2, and lines 26 of a chuck of data have been printed to a file:

# This is a data file used for blockA.
% 10576 A 10 0 1
CF
# This is a data file used for blockA.
% 10576 B 20 1 2
AA
# This is a data file used for blockA.
% 10576 C 30 2 3
7F

---------
I tried using sed -n -e '1,2p;26p' inputfile.txt but that only prints the 1st, 2nd, and 26th line of chunk1. It doesn't output the data every chunk.

I also tried sed -n '0~26p' inputfile.txt, but that only prints the 26th line of every chunk.

Thanks for your help

assuming your given counts are correct and there are no blank lines in the file

awk '{
        cnt++
        if(cnt==1 | cnt ==2 || cnt==26) {print $0; cnt=(cnt==26)?0 :cnt}
        else {next}

       }' inputfile > outputfile
             

try that on your data

Try...

awk 'NR%26<3' file1
1 Like