I'm using zsh on a MacBook Pro, OS X 10.10. When I type in certain commands, such as this one:
cat myfile | awk -F $'\t' '{print $8, $9}' | sort | uniq -c | sort -k1,1n | awk '{if ($1 > 50) sum += $1} END {print sum}'
, then part of the command is repeated before the actual output of the command. The output in this case looks like:
" '{print $8, $9}' | sort | uniq -c | sort -k1,1n | awk '{if ($1 > 50) sum += $1} END {print sum}' : myusername2525
Does anybody know how to get of the jumbled output? It kind of looks like a format string vulnerability or something similar to me.
Best Answer
The problem is the
$
in the firstawk
statement in the chain:The
-F
option forawk
sets the record separator for your input. If you're really expecting the separator to be a dollar sign followed by a tab character you should move the dollar sign in to the single quotes like so:Leaving the
$
outside the single quotes means it's being interpreted by the shell as a variable reference. This is what's leading to your weird output. If you aren't expecting a dollar sign in the field separator, only a tab, change theawk
call to:Based on what you've said, the above appears to be what you want.