Advertisement
dropbox1349

AWK (windows), stream editor - formattare testo rimuovendo duplicati e preservando l'ordine righe

Feb 4th, 2021
3,549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.94 KB | None | 0 0
  1. Video youtube
  2. https://youtu.be/iXtCtCXcgDk
  3.  
  4. Codice AWK
  5. ---------------------------------------------------------
  6.  
  7. BEGIN{FS=OFS=";"}
  8. {sub(/;$/,"")}
  9. NR==FNR{
  10.     for (i=1;i<=NF;++i)
  11.         for (j=1;j<=NF;++j)
  12.             if (j!=i&&!b[$i,$j]++)
  13.                 a[$i,++c[$i]]=$j
  14.     next
  15. }
  16. {
  17.     delete b
  18.     for (i=1;i<=NF;++i)
  19.         ++b[$i]
  20.     for (i=1;i<=NF;++i)
  21.         for (j=1;j<=c[$i];++j)
  22.             if (!b[a[$i,j]]++)
  23.                 $(NF+1)=a[$i,j]
  24.     print
  25. }
  26.  
  27.  
  28. -----------------------------------------------------------------
  29. Come utilizzarlo:
  30.  
  31. Andare al percorso dove è installato awk, assicurarsi che i 2 file di testo siano nella stessa cartella e poi digitare
  32.  
  33. awk -f script.awk 2.txt 1.txt
  34.  
  35. In pratica da questi due file di testo
  36.  
  37. 1.txt
  38.  
  39. UU;    
  40. AA;BB;
  41. ZZ;KK;
  42.  
  43. 2.txt
  44.  
  45. CC;DD;BB;AA;
  46. LL;KK;
  47. GH;ZZ;SS;
  48.  
  49. Si genera un terzo file di testo cosi formattato
  50.  
  51. UU;
  52. AA;BB;CC;DD;
  53. ZZ;KK;LL;GH;SS;
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement