How to solve "Broken Pipe" error when using awk with head
Posted
by
Jon
on Super User
See other posts from Super User
or by Jon
Published on 2011-11-28T15:23:41Z
Indexed on
2011/11/28
18:10 UTC
Read the original article
Hit count: 493
I'm getting broken pipe errors from a command that does something like:
ls -tr1 /a/path | awk -F '\n' -vpath=/prepend/path/ '{print path$1}' | head -n 50
Essentially I want to list (with absolute path) the oldest X files in a directory.
What seems to happen is that the output is correct (I get 50 file paths output) but that when head has output the 50 files it closes stdin causing awk to throw a broken pipe error as it is still outputting more rows.
© Super User or respective owner