![]() |
|
|
google unix.com
|
|||||||
| Forum | Registrati | Regole Forum | Collegamenti | Album | FAQ | Members List | Calendario | Ricerca | Today's Posts | Mark Forums Read |
| Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui. |
Più di UNIX e Linux Forum Argomenti potreste trovare utili
|
||||
| Filo | Thread Starter | Forum | Risposte | Ultimo Post |
| Conte numero di occorrenze di una parola | shikhakaul | UNIX for Dummies Domande & Risposte | 8 | 06-25-2009 12:10 PM |
| PERL: Semplice reg expr convalidare numero 6 cifre | BufferExploder | Shell scripting e di programmazione | 2 | 09-10-2008 12:15 PM |
| Conta il numero di eventi da file perticular parola | rinku | Shell scripting e di programmazione | 40 | 08-10-2007 08:33 PM |
| parole mostrando sbagliato numero di linee | tselvanin | UNIX for Dummies Domande & Risposte | 3 | 01-06-2004 11:33 PM |
| limitare il numero di cifre di un PID | mlefebvr | UNIX e avanzata per utenti esperti | 1 | 05-27-2002 10:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Cerca in questo Thread |
Rating:
|
Modalità di visualizzazione |
|
|
|
||||
|
Potrebbe ci mostrano come si utilizzi questo codice nel vostro script? Se si desidera salvare in una variabile di provare qualcosa di simile a questo:
Codice:
COUNT=`echo $WORD | grep -oE [[:digit:]] | wc -l` |
|
|||||
|
c'è qualche altro problema ...
Lasciate che vi dica esattamente ciò che voglio
Ho una parola che hanno 8 chrs, qualcosa come abc12345 o ab123456 Ora, se chrs ultimi cinque cifre sono poi voglio fare qualche altra operazione Ho usato il codice Codice:
if [ `echo $WORD | cut -c 4-8 | grep -oE [[:digit:]] | wc -l` -eq 5 ] then do this... |
|
||||
|
Codice:
$ cat ./testgrep.ksh
#!/bin/ksh
WORD=abc12345
echo $WORD|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
echo "Do this with $WORD"
else
echo "Else do this with $WORD"
fi
WORD2=ab123456
echo $WORD2|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
echo "Do this with $WORD2"
else
echo "Else do this with $WORD2"
fi
WORD3=abc1234
echo $WORD3|grep -qE "[[:digit:]]{5}$"
if [ $? -eq 0 ]; then
echo "Do this with $WORD3"
else
echo "Else do this with $WORD3"
fi
exit 0
$ ./testgrep.ksh
Do this with abc12345
Do this with ab123456
Else do this with abc1234
|
|
|||||
|
Citazione:
Codice:
$ WORD=abcd1234
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
KO
$ WORD=abcd12345
$ [[ $WORD =~ [0-9]{5}$ ]] && echo OK || echo KO
OK
|
![]() |
| Segnalibri |
| Tag |
| perl, perl turno, spostamento, spostamento perl |
| Thread Tools | Cerca in questo Thread |
| Modalità di visualizzazione | Vota questo thread |
|
|