and yess, g/PATTERN/ and /v/PATTERN/ are supzr powerful, creating branch conditions based on wether or not they (do not)match a PATTERN.
based on what you wrote:
i just add trailing \n normalization at the end
, x/(.+\n)+|\n+/ { g/./ x/\n/ c/ / v/./ c/\n/ } $ a/\n/ , x/\n+$/ c/\n/ w file_out.txt q