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.

expand<br />

unexpand<br />

cut<br />

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

# + punteggiatura, come i punti e virgola.<br />

# 2) Mo<strong>di</strong>ficatelo per filtrare anche gli spazi multipli e gli altri<br />

# + caratteri <strong>di</strong> spaziatura.<br />

bash$ cat fileprova<br />

Questa riga è presente una sola volta.<br />

Questa riga è presente due volte.<br />

Questa riga è presente due volte.<br />

Questa riga è presente tre volte.<br />

Questa riga è presente tre volte.<br />

Questa riga è presente tre volte.<br />

bash$ ./wf.sh fileprova<br />

6 riga<br />

6 questa<br />

6 presente<br />

6 è<br />

5 volte<br />

3 tre<br />

2 due<br />

1 volta<br />

1 una<br />

1 sola<br />

Il filtro expand trasforma le tabulazioni in spazi. È spesso usato in una pipe.<br />

Il filtro unexpand trasforma gli spazi in tabulazioni. Esegue l’azione opposta <strong>di</strong> expand.<br />

Strumento per estrarre i campi dai file. È simile alla serie <strong>di</strong> coman<strong>di</strong> print $N <strong>di</strong> awk, ma con<br />

capacità più limitate. In uno script è più semplice usare cut che non awk. Particolarmente<br />

importanti sono le opzioni -d (delimitatore) e -f (in<strong>di</strong>catore <strong>di</strong> campo - field specifier).<br />

Usare cut per ottenere l’elenco dei filesystem montati:<br />

cut -d ’ ’ -f1,2 /etc/mtab<br />

Uso <strong>di</strong> cut per visualizzare la versione del SO e del kernel:<br />

249

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

Saved successfully!

Ooh no, something went wrong!