I have a text file with empty lines separating blocks of text. I would like to use *NIX command-line tools to shuffle this file while respecting the block structure. In other words, in the output I would like to see the changed order of blocks; the lines and their order inside the block remain the same.
Input file example:
line 1
line 2
line 10
line 20
line 30
line 100
line 200
The output file (after shuffle):
line 10
line 20
line 30
line 1
line 2
line 100
line 200
Of course, running repeatedly should give different order of blocks.
The first line of the file is always non-empty. There are no double blank lines. The last line of the file is always empty.
I wrote a very simple Python script that reads all lines in a list of lists, shuffles it and outputs. I am curious whether I could do it with standard *NIX tools.