#!/usr/bin/awk -f /^From / { if (not_blank == 0) { if (file > 0) { close(file) } file += 1; } } { not_blank=1 if (file > 0) { print > file } } /^$/ { not_blank=0 } /^[\015]$/ { not_blank=0 } BEGIN { file = 0 } END { if (file > 0) { close(file) } }