I need to split a .txt
file into smaller ones containing 100 lines each, including the header. I don't know if this is relevant, but the original file is delimited like this:
COLUMN1 | COLUMN2 | COLUMN3
1 | 2 | 3
4 | 5 | 6
7 | 8 | 9
I need every file generated from this split to have the header line. Also, they need to be generated in/moved to another directory and follow a name pattern, like file_01.txt
, file_02.txt
, etc
Best Answer
With
gnu split
you could save the header in a variable thensplit
starting from the 2nd line, using the--filter
option to write the header first and then the 99 lines for each piece and also specify the output directory (e.g.path to/output dir/
):this will create 100-lines pieces as