Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi N - Z > Sistemi operativi I > Esercizio esame lab
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Post New Thread    Post A Reply
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Esercizio esame lab

Ciao a tutti, mi sto preparando in vista dell'esame di sistemi operativi di gennaio e c'è un esercizio, che mi è capitato all'esame di laboratorio con Monga, che non riesco proprio a risolvere. Il testo dell'esercizio diceva:

trovare tutti i file .c e contare il numero di caratteri nel loro nome.
Compresa la loro estensione, esempio pippo.c=7.

Qualcuno saprebbe darmi una mano?

20-11-2016 16:10
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cronovirus
dsy core staff

User info:
Registered: Jun 2012
Posts: 471 (0.11 al dì)
Location:
Corso: Magistrale in Informatica
Anno: 2
Time Online: 4 Days, 2:45:03: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Con la find trovi tutti i nomi dei file .c e con una opsione li stampi tutti di fila, poi in pipe conti i caratteri :)

20-11-2016 19:57
Click Here to See the Profile for Cronovirus Click here to Send Cronovirus a Private Message Find more posts by Cronovirus Add Cronovirus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Sì, sull'idea su come procedere non ho grossi problemi. Il fatto è che una volta trovati i file .c, contate le linee dei nomi, non riesco a contare il numero di caratteri delle linee praticamente, che poi sarebbero i nomi dei file.

22-11-2016 10:19
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Praticamente mi manca l'ultimo passaggio, perché finché si tratta di trovarli e stamparli, non ho problemi.

22-11-2016 10:20
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cronovirus
dsy core staff

User info:
Registered: Jun 2012
Posts: 471 (0.11 al dì)
Location:
Corso: Magistrale in Informatica
Anno: 2
Time Online: 4 Days, 2:45:03: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

usa 'wc -c'

22-11-2016 15:24
Click Here to See the Profile for Cronovirus Click here to Send Cronovirus a Private Message Find more posts by Cronovirus Add Cronovirus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Alla fine ci sono riuscito, se a qualcuno può interessare, ho fatto così:

sudo find / -type f -name "*.c" | rev | cut -d "/" -f1 | rev | wc -m

22-11-2016 15:41
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
PrizeD
.consigliere.

User info:
Registered: Dec 2007
Posts: 140 (0.02 al dì)
Location: Cerro Maggiore
Corso: Informatica
Anno:
Time Online: 20:00:39 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Cic
Alla fine ci sono riuscito, se a qualcuno può interessare, ho fatto così:

sudo find / -type f -name "*.c" | rev | cut -d "/" -f1 | rev | wc -m


Ciao, stavo provando anche io a fare questo esercizio, e mi sono accorto che facendo così vengono contati anche gli \n presenti. Alla fine sono arrivato a:

sudo find / -type f -name "*.c" | cut -d "/" -f2 | xargs printf "%s" | wc -m

Usando printf al posto di echo non c'è più il problema di \n letti a fine riga.

Last edited by PrizeD on 29-12-2016 at 18:35

29-12-2016 16:06
Click Here to See the Profile for PrizeD Click here to Send PrizeD a Private Message Find more posts by PrizeD Add PrizeD to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cronovirus
dsy core staff

User info:
Registered: Jun 2012
Posts: 471 (0.11 al dì)
Location:
Corso: Magistrale in Informatica
Anno: 2
Time Online: 4 Days, 2:45:03: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

find ./ -type f -name "*.c" -printf "%f" | wc -c

29-12-2016 20:39
Click Here to See the Profile for Cronovirus Click here to Send Cronovirus a Private Message Find more posts by Cronovirus Add Cronovirus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
PrizeD
.consigliere.

User info:
Registered: Dec 2007
Posts: 140 (0.02 al dì)
Location: Cerro Maggiore
Corso: Informatica
Anno:
Time Online: 20:00:39 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Cronovirus
find ./ -type f -name "*.c" -printf "%f" | wc -c


Ma "wc -c" non stampa il numero di byte di un file?

29-12-2016 21:07
Click Here to See the Profile for PrizeD Click here to Send PrizeD a Private Message Find more posts by PrizeD Add PrizeD to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cronovirus
dsy core staff

User info:
Registered: Jun 2012
Posts: 471 (0.11 al dì)
Location:
Corso: Magistrale in Informatica
Anno: 2
Time Online: 4 Days, 2:45:03: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

si, nota che un carattere è un byte e quindi è giusto. Puoi usare anche wc -m, non cambia niente

29-12-2016 21:09
Click Here to See the Profile for Cronovirus Click here to Send Cronovirus a Private Message Find more posts by Cronovirus Add Cronovirus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
PrizeD
.consigliere.

User info:
Registered: Dec 2007
Posts: 140 (0.02 al dì)
Location: Cerro Maggiore
Corso: Informatica
Anno:
Time Online: 20:00:39 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Si, ma l'esercizio era di contare i caratteri contenuti nel nome. E inoltre, rimane il problema degli \n, che con molta probabilità vengono contati da -c

29-12-2016 21:40
Click Here to See the Profile for PrizeD Click here to Send PrizeD a Private Message Find more posts by PrizeD Add PrizeD to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cronovirus
dsy core staff

User info:
Registered: Jun 2012
Posts: 471 (0.11 al dì)
Location:
Corso: Magistrale in Informatica
Anno: 2
Time Online: 4 Days, 2:45:03: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

prova per credere

29-12-2016 22:05
Click Here to See the Profile for Cronovirus Click here to Send Cronovirus a Private Message Find more posts by Cronovirus Add Cronovirus to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ha ragione Cronovirus, con la soluzione proposta da lui, non vengono contati gli \n. Grazie.

04-01-2017 12:02
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
PrizeD
.consigliere.

User info:
Registered: Dec 2007
Posts: 140 (0.02 al dì)
Location: Cerro Maggiore
Corso: Informatica
Anno:
Time Online: 20:00:39 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Scusa Cic se mi riaggancio al tuo post, ma evito di aprirne uno nuovo.
Stavo facendo questo esercizio:

- Trovare tutti i file che abbiano lo stesso numero di blocchi

count=0; prevf=""; prevb=0; find / -type f | head -20 | while read file; do blocks=$(stat -c %b $file); echo "$blocks $file"; done | sort -n | while read blocks file; do if [ $count -eq 0 ]; then prevb=$blocks; prevf=$file; fi; ((count++)); if [ $blocks -ne $prevb ]; then if [ $count -gt 2 ]; then echo "$prevb BLOCKS $prevf"; fi; prevb=$blocks; prevf=$file; count=1; fi; if [ $count -gt 1 ]; then echo "$prev BLOCKS $prevf"; prevf=$file; fi; done


In pratica leggo tutti i file e li stampo con il relativo numero di blocchi, riordino e stampo solo se trovo più di 1 file con un certo numero di blocchi. (head -20 l'ho messo per velocizzare le prove)

Che ne pensate? Come avreste fatto voi? (commenti e correzioni al codice sono più che ben accetti)

Last edited by PrizeD on 16-01-2017 at 15:52

16-01-2017 15:41
Click Here to See the Profile for PrizeD Click here to Send PrizeD a Private Message Find more posts by PrizeD Add PrizeD to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Cic
.fedelissimo.

User info:
Registered: Jul 2009
Posts: 44 (0.01 al dì)
Location:
Corso:
Anno:
Time Online: 16:21:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Sembra andare bene, al momento non mi vengono in mente altre soluzione. Se ne trovo una alternativa, la pubblicherò.

16-01-2017 16:23
Click Here to See the Profile for Cic Click here to Send Cic a Private Message Find more posts by Cic Add Cic to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 07:32.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.044 seconds (79.24% PHP - 20.76% MySQL) con 25 query.