BEGIN { uid="" summary="" related="" FS=":" printf("%s,%s,%s\n","uid","summary","related"); } ($1 == "BEGIN"){ uid="" summary="" related="" } ($1 == "UID"){ uid=$2 } ($1 == "SUMMARY"){ summary=$2 } ($1 == "RELATED-TO"){ related=$2 } ($1 == "END" && uid != ""){ printf("%s,%s,%s\n",uid,summary,related); uid="" summary="" related="" }