http://www.perlmonks.org?node_id=1013641

brad_nov has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes
11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|...... 21|7|def|207048|114424|...... 23|7|geh|227947|112191|...... 26|32|fgh|248846|109958|...... 27|23|abc|269745|107725|...... 29|34|def|290644|105492|...... 30|32|geh|311543|103259|...... 33|23|fgh|332442|101026|...... 35|34|abc|353341|98793|...... 37|7|def|374240|96560|...... 39|4|geh|395139|94327|...... 41|2|fgh|416038|92094|...... 44|23|abc|436937|89861|...... 46|1|def|457836|87628|...... 48|3|geh|478735|85395|...... 50|23|fgh|499634|83162|......
I am trying to split the files based on the 2nd column like below sample_1_1.txt
11|1|abc|102553|125589|...... 14|1|abc|186149|116657|...... 46|1|def|457836|87628|......
sample_1_2.txt
10|2|def|123452|123356|...... 13|2|geh|144351|121123|...... 41|2|fgh|416038|92094|......
sample_1_3.txt
48|3|geh|478735|85395|......
and so on Could some help me on this. Thanks in advance