reorganiza o texto em sentenças

0

tem um arquivo de texto como este:

group0          Level          1
name                   Matty1
name nickname        member4
name                   Matty2
name nickname        member14
group1          Level          1
name                   sanders1
name nickname        member0
name                   sanders2
name nickname        member1
name                   sanders3
name nickname        member2
name                   sanders4
name nickname        member3
group2          Level          2
name                   Kendal1
name nickname        member5
name                   Kendal2
name nickname        member15
group3          Level          2
name                   colen1
name nickname        member6
name                   colen2
name nickname        member7
name                   colen3
name nickname        member8

Eu quero organizar as palavras em frases e, em seguida, ordená-las pelo ID do membro

member-0 sanders1 group1 1
member-1 sanders2 group1 1
member-2 sanders3 group1 1
member-3 sanders4 group1 1
member-4 Matty1 group0 1
member-5 Kendal1 group2 2
member-6 colen1 group3 2
member-7 colen2 group3 2
member-8 colen3 group3 2
member-14 Matty2 group0 1
member-15 Kendal2 group2 2
    
por Kenan 10.10.2018 / 20:01

2 respostas

0
awk '$2=="nickname"{print $3,name,group,digit;next}$1=="name"{name=$2;next}{group=$1;digit=$NF}' file | sed 's/member/member-/g' | sort -n -t- -k 2

member-0 sanders1 group1 1
member-1 sanders2 group1 1
member-2 sanders3 group1 1
member-3 sanders4 group1 1
member-4 Matty1 group0 1
member-5 Kendal1 group2 2
member-6 colen1 group3 2
member-7 colen2 group3 2
member-8 colen3 group3 2
member-14 Matty2 group0 1
member-15 Kendal2 group2 2
    
por 10.10.2018 / 20:08
0

Apenas uma chamada para o awk:

$ awk -vOFS='\t' '
      /^group/{group=$1;level=$3};
      $1=="name" && $2!="nickname" {name=$2};
      $2=="nickname"{o[++i]=gensub(/member/,"",1,$3)" "name" " group" " level};
      END{
          asort(o,p,"@val_num_asc");
          for(i in p){print "member-"p[i]}
      }' file

member-0 sanders1 group1 1
member-1 sanders2 group1 1
member-2 sanders3 group1 1
member-3 sanders4 group1 1
member-4 Matty1 group0 1
member-5 Kendal1 group2 2
member-6 colen1 group3 2
member-7 colen2 group3 2
member-8 colen3 group3 2
member-14 Matty2 group0 1
member-15 Kendal2 group2 2
    
por 11.10.2018 / 11:31