11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

paste<br />

join<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

Strumento per riunire più file in un unico file impaginato su <strong>di</strong>verse colonne. In combinazione con<br />

cut è utile per creare file <strong>di</strong> log <strong>di</strong> sistema.<br />

Lo si può considerare il cugino specializzato <strong>di</strong> paste. Questa potente utility consente <strong>di</strong> fondere<br />

due file in modo da fornire un risultato estremamente interessante. Crea, in sostanza, una versione<br />

semplificata <strong>di</strong> un database relazionale.<br />

Il comando join opera solo su due file, ma unisce soltanto quelle righe che possiedono una<br />

corrispondenza <strong>di</strong> campo comune (solitamente un’etichetta numerica) e visualizza il risultato allo<br />

stdout. I file che devono essere uniti devono essere anche or<strong>di</strong>nati in base al campo comune, se si<br />

vuole che l’abbinamento delle righe avvenga correttamente.<br />

File: 1.dat<br />

100 Scarpe<br />

200 Lacci<br />

300 Calze<br />

File: 2.dat<br />

100 EUR 40.00<br />

200 EUR 1.00<br />

300 EUR 2.00<br />

bash$ join 1.dat 2.dat<br />

File: 1.dat 2.dat<br />

100 Scarpe EUR 40.00<br />

200 Lacci EUR 1.00<br />

300 Calze EUR 2.00<br />

Nota: Il campo comune, nell’output, compare una sola volta.<br />

251

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!