Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • This is really, really close to being a perfect/correct solution. Does sh not contain any builtins, or POSIX prescribe any similar functions, to mimic awk's functionality here, but without interfering in the text? Commented May 4, 2020 at 19:05
  • @KamilMaciorowski, you're making very good points, and I've incorporated some in my answer. A note however: though some awk implementations will choke on NUL and extra-long lines, they are required do deal with non-delimited lines. Commented May 5, 2020 at 5:58
  • 1
    Now I see a broader picture. After reading the definition of "shall" I understand "input files shall be text files" does not imply "non-text files may be unsupported because they don't meet the requirement". It means "the utility must support text files and may still be obliged to support (some) other files". So "input files shall" is not about the files, it's about the utility. In particular for awk "input files shall be text files", still RS may be something else than a newline, so the input may totally not comply with the formal definitions of "text file" and "line". Lesson learned. Commented May 5, 2020 at 6:58
  • It appears that { ($cmd 2>&3 3>&-) | perl -0777 -pe '' 3>&- ; } 3>&1 works perfectly. Commented May 6, 2020 at 18:35