2016-01-15 7 views
-2

Может ли кто-нибудь помочь мне в том, как поворачивать стол в оболочке?сводная таблица в оболочке

пример:

вход:

USER  QUESTION   ANSWER 
USER1  how old are you  15 
USER1  where do you live america 
USER1  are you married  no 
USER2  how old are you  54 
USER2  where do you live USA 
USER2  are you married  Yes 
USER3  how old are you  21 
USER3  where do you live Germany 
USER3  are you married  no 

Желаемый результат:

User How old are you  where do you live  are you married 
USER1 15     america    no 
USER2 54     USA     Yes 
USER3 21     Germany    no 

ответ

0

вот мое предложение:

echo "User How old are you  where do you live  are you married" 
    cat input| awk '{line="";for (i = 2; i <= NF; i++) line = line $i " "; table[$1]=table[$1] line;} END {for (key in table) print key " => " table[key];}' | cut -d' ' -f1,7,12,16 

Во-первых, сцепить строки, которые похожи thei г первый столбец:

cat input| awk '{line="";for (i = 2; i <= NF; i++) line = line $i " "; table[$1]=table[$1] line;} END {for (key in table) print key " => " table[key];}' 

enter image description here

мы хотим, 16. так что я использовал вырезать команду 1,7,12.
enter image description here

Смежные вопросы