使用AWK重新排序列

oww*_*w14 5 awk command-line multiple-columns

我需要重新排序此(制表符分隔)数据的列:

   1 cat    plays
   1 dog    eats
   1 horse  runs
   1 red    dog
   1 the    cat
   1 the    cat
Run Code Online (Sandbox Code Playgroud)

所以这是打印像:

cat plays   1
dog eats    1
horse   runs    1
red dog 1
the cat 2
Run Code Online (Sandbox Code Playgroud)

我试过了:

sort [input] | uniq -c | awk '{print $2 "\t" $3 "\t" $1}' > [output]
Run Code Online (Sandbox Code Playgroud)

结果是:

1   cat 1
1   dog 1
1   horse   1
1   red 1
2   the 1
Run Code Online (Sandbox Code Playgroud)

谁能给我一些关于出了什么问题的见解?谢谢.

pNr*_*Nre 6

由于输出cat input | sort | uniq -c是:

   1    1 cat    plays
   1    1 dog    eats
   1    1 horse  runs
   1    1 red    dog
   2    1 the    cat
Run Code Online (Sandbox Code Playgroud)

你需要这样的东西:

cat input | sort | uniq -c | awk '{print $3 "\t" $4 "\t" $1}'
Run Code Online (Sandbox Code Playgroud)