I am looking for a code able to concatenate different .txt files but just up to certain number of lines in each one.
Suppose we have many text files as follows:
file1.txt:
AAAAA
BBBBB
CCCCC
DDDDD
EEEEE
file2.txt:
FFFFF
GGGGG
HHHHH
IIIII
JJJJJ
file3.txt:
KKKKK
LLLLL
MMMMM
NNNNN
OOOOO
file4.txt:
PPPPP
QQQQQ
RRRRR
SSSSS
TTTTT
How can we make one log file like below (assuming that all of them must be concatenated only up to the line number 3 -included)?
result:
AAAAA
BBBBB
CCCCC
FFFFF
GGGGG
HHHHH
KKKKK
LLLLL
MMMMM
PPPPP
QQQQQ
RRRRR
This is for Python 3.7.3. I was succesful to concatenate the files using the examples available in:
but I was not able to modify the code for a specific maximum number of lines per file.
Related code developed until now (but not successful):
    a = open('newfile.log', 'wb')
    with a as wfd:
            for f in glob.glob(r'*.txt'):
                    with open(f,'rb') as fd:
                            for line in fd:
                                    for line in range (0, 3):
                                            a.write(line)  
Any help?
The obtained error message says:
TypeError: a bytes-like object is required, not 'int'
 
     
     
     
    