I define a 'block' of text as all lines between start of file, newline or end of file:
block1
block2
block3
anotherblock4
anotherblock5
anotherblock6
lastblock7
lastblock8
Any text can occupy a block - it is unknown what lines are there. I tried to write a shell script to insert a new line at the 2nd block, but since sed doesn't like working with newlines, I hacked around this sed oneliner:
sed -n "H;\${g;s/\n\n/\nTEST\n\n/2;p}"
This results into:
[newline]
block1
block2
block3
anotherblock4
anotherblock5
anotherblock6
TEST
lastblock7
lastblock8
The problem is, it adds a newline to the start of the buffer (marked as [newline] because StackOverflow's markup cannot show it) Is there another way to do it using a different tool or different regexp?