leave a new line only before a pattern
i need to reformat a file in shell, so i only leave the 'new line' before some pattern. Ex:
Europe First Asia Second Africa Third Australia Fourth Europe Sixth Australia Seventh Europe Eight America Last
Europe FirstAsia SecondAfrica ThirdAustralia Fourth Europe SixthAustralia Seventh Europe EightAmerica Last
where the pattern is "Europe"
perl -i -0777pe's/\n(?!Europe|\z)/ /g' file