$3=="P" { for(i=4; i<=NF; i++) line = sprintf("%s%s%s", line, $(i), OFS); } $3=="F" { printf("%s%s%s%s%s", $1, OFS, $2, OFS, line) for(i=4; i<=NF; i++) printf("%s%s", $(i), i<NF ? OFS : "\n"); line="" }