diff --git a/101/012_elaborare_flussi_di_testo.md b/101/012_elaborare_flussi_di_testo.md index 34fce9e..c526e3e 100644 --- a/101/012_elaborare_flussi_di_testo.md +++ b/101/012_elaborare_flussi_di_testo.md @@ -180,4 +180,152 @@ echo "new line" >> ftu.txt sha256sum -c sha256sum.txt ftu.txt: NON RIUSCITO sha256sum: WARNING: 1 computed checksum did NOT match +``` + +### Esercizi + +```bash +root:x:0:0:root:/root:/bin/bash +daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin +bin:x:2:2:bin:/bin:/usr/sbin/nologin +sys:x:3:3:sys:/dev:/usr/sbin/nologin +sync:x:4:65534:sync:/bin:/bin/sync +nvidia-persistenced:x:121:128:NVIDIA Persistence Daemon,,,:/nonexistent:/sbin/nologin +libvirt-qemu:x:64055:130:Libvirt Qemu,,,:/var/lib/libvirt:/usr/sbin/nologin +libvirt-dnsmasq:x:122:133:Libvirt Dnsmasq,,,:/var/lib/libvirt/dnsmasq:/usr/sbin/nologin +carol:x:1000:2000:Carol Smith,Finance,,,Main Office:/home/carol:/bin/bash +dave:x:1001:1000:Dave Edwards,Finance,,,Main Office:/home/dave:/bin/ksh +emma:x:1002:1000:Emma Jones,Finance,,,Main Office:/home/emma:/bin/bash +frank:x:1003:1000:Frank Cassidy,Finance,,,Main Office:/home/frank:/bin/bash +grace:x:1004:1000:Grace Kearns,Engineering,,,Main Office:/home/grace:/bin/ksh +henry:x:1005:1000:Henry Adams,Sales,,,Main Office:/home/henry:/bin/bash +john:x:1006:1000:John Chapel,Sales,,,Main Office:/home/john:/bin/bash +``` + +- Elenca solo gli utenti del gruppo 1000 + +```bash +[20:21 sab nov 02]dado@pc (957):~ + > grep 1000 passwd +carol:x:1000:2000:Carol Smith,Finance,,,Main Office:/home/carol:/bin/bash +dave:x:1001:1000:Dave Edwards,Finance,,,Main Office:/home/dave:/bin/ksh +emma:x:1002:1000:Emma Jones,Finance,,,Main Office:/home/emma:/bin/bash +frank:x:1003:1000:Frank Cassidy,Finance,,,Main Office:/home/frank:/bin/bash +grace:x:1004:1000:Grace Kearns,Engineering,,,Main Office:/home/grace:/bin/ksh +henry:x:1005:1000:Henry Adams,Sales,,,Main Office:/home/henry:/bin/bash +john:x:1006:1000:John Chapel,Sales,,,Main Office:/home/john:/bin/bash + +[20:21 sab nov 02]dado@pc (958):~ + > sed -n /1000/p < passwd +carol:x:1000:2000:Carol Smith,Finance,,,Main Office:/home/carol:/bin/bash +dave:x:1001:1000:Dave Edwards,Finance,,,Main Office:/home/dave:/bin/ksh +emma:x:1002:1000:Emma Jones,Finance,,,Main Office:/home/emma:/bin/bash +frank:x:1003:1000:Frank Cassidy,Finance,,,Main Office:/home/frank:/bin/bash +grace:x:1004:1000:Grace Kearns,Engineering,,,Main Office:/home/grace:/bin/ksh +henry:x:1005:1000:Henry Adams,Sales,,,Main Office:/home/henry:/bin/bash +john:x:1006:1000:John Chapel,Sales,,,Main Office:/home/john:/bin/bash +``` + +- Elenca solo i nomi completi di questi utenti + +```bash +[20:23 sab nov 02]dado@pc (962):~ + > sed -n /1000/p < passwd | cut -d : -f 5 | cut -d , -f 1 +Carol Smith +Dave Edwards +Emma Jones +Frank Cassidy +Grace Kearns +Henry Adams +John Chapel +``` + +- Un comando che seleziona un utente a caso del Main Office + +```bash +[20:26 sab nov 02]dado@pc (971):~ + > sed -n /Main\ Office/p < passwd | cut -d : -f 5 | cut -d , -f 1 | sort -R | head -n 1 + ``` + +- Quante persone lavorano in Finance, Engineering e Sales? + +```bash +[20:28 sab nov 02]dado@pc (978):~ + > grep -iE "finance|engineering|sales" passwd | wc -l +7 + +[20:28 sab nov 02]dado@pc (979):~ + > grep -iE "finance" passwd | wc -l +4 + +[20:30 sab nov 02]dado@pc (981):~ + > grep -iE "engineering" passwd | wc -l +1 + +[20:30 sab nov 02]dado@pc (982):~ + > grep -iE "sales" passwd | wc -l +2 + +[21:09 sab nov 02]dado@pc (1108):~ + > sed -n /Main\ Office/p < passwd | cut -d , -f 2 | sort | uniq -c + 1 Engineering + 4 Finance + 2 Sales +``` + +- Creare un file .csv col formato seguente + +```bash +First Name, Last Name, Position + + +[20:40 sab nov 02]dado@pc (1016):~ + > sed -n /Main\ Office/p < passwd | cut -d : -f 5 | cut -d , -f 1,2 | cut -d " " -f 1,2 --output-delimiter=, > names.csv +Carol,Smith,Finance +Dave,Edwards,Finance +Emma,Jones,Finance +Frank,Cassidy,Finance +Grace,Kearns,Engineering +Henry,Adams,Sales +John,Chapel,Sales +``` + +- Assicurasi l'integrita' del file precedente tramite `md5sum`: + +```bash +[20:44 sab nov 02]dado@pc (1024):~ + > md5sum names.csv > md5sum_names.txt + +[20:45 sab nov 02]dado@pc (1026):~ + > md5sum -c md5sum_names.txt +names.csv: OK + +[20:45 sab nov 02]dado@pc (1027):~ + > echo "new line" >> md5sum_names.txt + +[20:46 sab nov 02]dado@pc (1028):~ + > md5sum -c md5sum_names.txt +names.csv: OK +md5sum: WARNING: 1 line is improperly formatted +``` + +- Dall'output di `ls -l /etc`, ottenere solo i nomi dei file + +```bash +[21:13 sab nov 02]dado@pc (1114):~ + > ls -l /etc/ | tr -s " " | cut -d " " -f 9 +``` + +- Nome e proprietario + +```bash +[21:13 sab nov 02]dado@pc (1114):~ + > ls -l /etc/ | tr -s " " | cut -d " " -f 9,3 +``` + +- SOLO i nomi delle cartelle e del proprietario + +```bash +[21:16 sab nov 02]dado@pc (1120):~ + > ls -l /etc/ | tr -s " " | grep ^d | cut -d " " -f 9,3 ``` \ No newline at end of file