Reputation: 3
i need to reformat a file in shell, so i only leave the 'new line' before some pattern. Ex:
Input:
Europe First
Asia Second
Africa Third
Australia Fourth
Europe Sixth
Australia Seventh
Europe Eight
America Last
Output:
Europe FirstAsia SecondAfrica ThirdAustralia Fourth
Europe SixthAustralia Seventh
Europe EightAmerica Last
where the pattern is "Europe"
Upvotes: 0
Views: 103
Reputation: 58430
This might work for you (GNU sed):
sed ':a;$!N;/\nEurope/!s/\n//;ta;P;D' file
Upvotes: 0
Reputation: 126722
Simply chomp
every line and print
it, preceding it with an additional newline if it starts with the pattern
perl -ne 'chomp; print "\n" if /^Europe/; print' myfile
Upvotes: 0