.dsy:it.
Show 150 posts per page

.dsy:it. (http://www.dsy.it/forum/)
- Sistemi operativi I (http://www.dsy.it/forum/forumdisplay.php?forumid=269)
-- Esercizio Monga (http://www.dsy.it/forum/showthread.php?threadid=44118)


Posted by Cic on 09-05-2017 12:23:

Esercizio Monga

Ciao, qualcuno saprebbe dirmi come fare questo esercizio?

Trovare i file che hanno numero di caratteri dispari nel nome.

Ho provato con:

find / -type f | while read line; do wc -m $line | awk '{if(($line%2)!=0) print $line};
done;

e con:

find / -type f -printf "%f\n" | wc -m $nome | awk '{if(($nome%2)!=0) print $nome}'

ma sembra non andare. Curiosamente se lo faccio sui fali .c sembra funzionare, ma in questi modi stampa anche file con numero di caratteri pari nel nome.


Posted by guidodl on 02-06-2017 09:26:

Ciao, io l' ho fatto con un programmino da eseguire da bash :)

#trovare i file che hanno un numero di caratteri dispari nel nome
mycounter=0
lstarget='/usr/include/'
for i in `ls $lstarget | grep -v ^d | cut -d '.' -f1`; do
nomefile=$(echo $i | cut -d '.' -f1)
ncaratteri=$(echo $i | wc -m)
ncaratteri=`expr $ncaratteri - 1`
test=$(( $ncaratteri % 2 ))
if [ $test -ne 0 ] ; then
echo $nomefile $ncaratteri
fi
done


Posted by Cic on 02-06-2017 11:17:

Ciao, grazie per la risposta :)
Una domanda, ma fi e done non devono essere seguiti da un ";"?


Posted by guidodl on 03-06-2017 10:12:

A quanto pare no. Infatti se lo salvi in un file di tipo .sh e lo esegui con bash <nomefile> funziona


Posted by Cic on 03-06-2017 11:03:

Ok proverò, grazie ancora. :) Perché se lo eseguo con ./nomefile mi dà degli errori.


All times are GMT. The time now is 06:49.
Show all 5 posts from this thread on one page

Powered by: vBulletin Version 2.3.1
Copyright © Jelsoft Enterprises Limited 2000 - 2002.