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.

uname -a | cut -d" " -f1,3,11,12<br />

Usare cut per estrarre le intestazioni dei messaggi da una cartella e-mail:<br />

bash$ grep ’^Subject:’ read-messages | cut -c10-80<br />

Re: Linux suitable for mission-critical apps?<br />

MAKE MILLIONS WORKING AT HOME!!!<br />

Spam complaint<br />

Re: Spam complaint<br />

Usare cut per la verifica <strong>di</strong> un file:<br />

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

# Elenca tutti gli utenti presenti nel file /etc/passwd.<br />

FILE=/etc/passwd<br />

for utente in $(cut -d: -f1 $FILE)<br />

do<br />

echo $utente<br />

done<br />

# Grazie, Oleg Philon per il suggerimento.<br />

cut -d ’ ’ -f2,3 nomefile equivale a awk -F’[ ]’ ’{ print $2, $3 }’<br />

nomefile<br />

Nota: È anche possibile usare l’a_capo come delimitatore. Il trucco consiste nell’inserire<br />

veramente un a_capo (INVIO) nella sequenza dei coman<strong>di</strong>.<br />

bash$ cut -d’<br />

’ -f3,7,19 filetesto<br />

Questa è la riga 3 <strong>di</strong> filetesto.<br />

Questa è la riga 7 <strong>di</strong> filetesto.<br />

Questa è la riga 19 <strong>di</strong> filetesto.<br />

Grazie a Jaka Kranjc per la precisazione.<br />

Ve<strong>di</strong> anche Esempio 12-43.<br />

250

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

Saved successfully!

Ooh no, something went wrong!