I have a file ~/bigfile.txt
that consists of thousands of blocks of text of the form
BLOCK NUMBER : <block>
SIZE : <size1> <size2>
EXTRA : <extraNumber>
<block of text>
For this example say
$ cat ~/bigfile.txt
BLOCK NUMBER : 1
SIZE : 7 6
EXTRA : 0
john paul
george ringo
BLOCK NUMBER : 2
SIZE : 7 3
EXTRA : -10
i am
the
walrus
BLOCK NUMBER : 3
SIZE : 4 3
EXTRA : -1024
hello world
I am trying to write a script that separates each block into a separate file named <block>-block.txt
, nested into subdirectories of ~/data/
indexed by <size1>
and <size2>
. For instance, running the script should result in
$ tree ~/data/
~/data/
|- 4-size1
|- 3-size2
|- 3-block.txt
|- 7-size1
|- 3-size2
|- 2-block.txt
|- 6-size2
|- 1-block.txt
Currently I have a script that simply dumps each block to a separate file in ~/data/
but I can't figure out how to alter it.
I can post my current script if that would help but I suspect that it's quite inefficient and not suited to tackle this sort of organizational task.
I would appreciate any pointers on how to accomplish this task with perl.