Splitting large File after line starts with %-

  Kiến thức lập trình

I have a large .txt file ~40mb which before reading in java I want to split in smaller files with a perl/shell script that the process can run better.

The Block parts are separated without % prefix, every block ends with %-, and Ideal would be to append the same prefix/block (starting with the same ID) beginnings in the same output file.

Input:
Input_File.TXT:
A000XXXXX %:20:012DKUSOA29EFGWT %:25:200999999 %:28C:ASDADF %- B66XXXXXX %:20:017TN24SDFSPGWT %:25:100444444 %:28C:S34 %- B66XXXXXX %:20:017TM0R9AZFXWGWT %:25:500888888 %:26:SADASD %:28:DD343 %-

Output:
A000XXXXX.TXT:
A000XXXXX %:20:012DKUSOA29EFGWT %:25:200999999 %:28C:ASDADF %-

B66XXXXXX.TXT:
B66XXXXXX %:20:017TN24SDFSPGWT %:25:100444444 %:28C:S34 %- B66XXXXXX %:20:017TM0R9AZFXWGWT %:25:500888888 %:26:SADASD %:28:DD343 %-

tried reading every line one by one but its not optimal by 40mb…

New contributor

Szymon Jelocha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT