Como extrair valores exclusivos da coluna #x com seus valores correspondentes da coluna # y?

0

I have a comma',' FS filename as csv with n number of columns. I need to extract the unique value from colm.#1 with only corresponding values in colm.#10. So basically the column 10 is the date which is always unique for colm.#1 despite the other columns.

echo filename 


colm.#1 colm.#2 colm.#3 colm.#4 colm.#5 colm.#6 colm.#7 colm.#8 colm.#9 colm.#10    colm.#11
    a   231 412 30.84873962 3   1   1   2013    5/28/2013   6/6/2006    299
    c   12  41  66.80690765 3   1   1   2014    5/25/2014   4/4/2004    351
    d   35  6   25.91622925 3   1   2   2013    6/27/2013   3/3/2003    303
    d   352 55  33.91288757 3   1   2   2014    6/26/2014   3/3/2003    355
    a   86  3   30.58783722 3   1   3   2013    7/24/2013   6/6/2006    307
    c   15  3242    26.6435585  3   1   3   2014    7/24/2014   4/4/2004    359
    e   67  1   22.95526123 3   1   4   2013    8/21/2013   5/5/2005    311
    a   464 64  4.804824352 3   1   4   2014    8/20/2014   6/6/2006    363
    b   66  42  29.42435265 3   1   5   2014    9/18/2014   7/7/2007    367
    m   24  2   66.10663319 3   1   6   2014    10/13/2014  9/9/2009    371

I tried the following command but it is only for colm#1 and I do not know how to get the corresponding value of the colm#10.

 cut -d',' -f1 filename |uniq

O resultado esperado seria:

a   6/6/2006
b   7/7/2007
c   4/4/2004
d   3/3/2003
e   5/5/2005
m   9/9/2009
    
por Daniel 12.12.2016 / 21:54

1 resposta

0

awk '{if ( ! ( $1 in Peers)) { Peers[$1]=$1 " " $10; print Peers[$1]} }' YourFile

isto leva a ordem como ela vem, se você precisar ordenar o resultado, um tipo em shel (entrada ou saída) ou (com o GNU awk)

awk '{if ( ! ( $1 in Peers)) Peers[$1]=$1 " " $10 } END{asort(Peers);for (Peer in Peers) print Peers[ Peer]}' YourFile
    
por 14.12.2016 / 14:25