#!/usr/bin/awk -f /^\$$/ { print >file close(file) file = "" next } { if (file == "") { file=$0 } print >file }