So, I'm seeing this output and I'm a bit surprised:
$ echo "a,b,c,d,e,f,g" | cut -d, -f-4
a,b,c,d
$ echo "a,b,c,d,e,f,g" | cut -d, -f6-
f,g
echo "a,b,c,d,e,f,g" | awk '{ print $0 | "cut -d, -f-4"; print $0 | "cut -d, -f6-"; }'
f,g
a,b,c,d
(As a side note, I realize this is a completely silly thing to do in awk
, but it's the only command I've seen it happen for!).
As I understand it, this should pipe the record into the two commands -- in order. But for some reason, the output appears reversed. If I do this instead
$ echo "a,b,c,d,e,f,g" | awk '{ print $0 | "echo hello"; print $0 | "echo goodbye"; }'
hello
goodbye
then everything comes in the order I expected. I'm thinking this must be some sort of race condition, but I'm surprised that awk
doesn't wait for the subcommand in the pipe to finish. Is this a known issue of using awk
or something pecular to gawk
? Is there any way to avoid such a pitfall?
EDIT:
I tried it using mawk
too... same (reversed) result, and seems to happen consistently for both.