2

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.

  • 2
    The problem is the $ in the first awk statement -- what are you trying to achieve with that that whole awk -F $'\t' '{print $8, $9}'? Are you really expecting your field separator to be a dollar sign followed by a tab character? Or are you trying to use $ to denote the start of the line? – Ian C. May 19 '15 at 5:54
  • I dunno, I had some problems with the escaped tab character a while ago and some people put a dollar sign before strings with escaped characters, so I thought this was standard behavior – Hinton May 19 '15 at 6:25
  • In any case, it's kinda strange that it just prints half the string back – Hinton May 19 '15 at 6:26
2

The problem is the $ in the first awk statement in the chain:

awk -F $'\t' '{print $8, $9}'

The -F option for awk 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:

awk -F '$\t' '{print $8, $9}'

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 the awk call to:

awk -F '\t' '{print $8, $9}'

Based on what you've said, the above appears to be what you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .