[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RES: [shell-script] Quebrar strings
From: |
Aurelio Marinho Jargas |
Subject: |
Re: RES: [shell-script] Quebrar strings |
Date: |
Fri, 18 Jun 2004 17:22:56 -0300 (ART) |
oi gilberto,
--- Gilberto Martins <address@hidden> escreveu:
> Como contar quantas vezes um dado caracter ocorre em uma strin?
> var="casa;bola;mundo;bela;boca;teste"
> Qual função me daria a quantidade de ";" nesta string ?
ou você usa a manha do IFS já citada pelo fernando, ou
apagar o lixo, deixando apenas os caracteres, e os conta.
o fernando também já mostrou como fazer isso usando o sed
e o wc, mas dá pra fazer só com os builtins do shell também:
$ var="casa;bola;mundo;bela;boca;teste"
$ num=${var//[^;]/} # apaga tudo o que nao for ;
$ echo $num
;;;;;
$ echo ${#num} # pega o tamanho da variável
5
ou um meio termo em um linha, com o wc
$ echo -n ${var//[^;]/} | wc -c
5
falou!
=====
--
Aurelio Marinho Jargas, Curitiba, Conectiva
A odisseia verde no FISL http://aurelio.net/curso/fisl
______________________________________________________________________
Yahoo! Mail - agora com 100MB de espaço, anti-spam e antivírus grátis!
http://br.info.mail.yahoo.com/
- Re: RES: [shell-script] Quebrar strings, Douglas, 2004/06/18
- Re: RES: [shell-script] Quebrar strings, Gilberto Martins, 2004/06/18
- Re: RES: [shell-script] Quebrar strings, Fernando Lemes da Silva, 2004/06/18
- Re: RES: [shell-script] Quebrar strings,
Aurelio Marinho Jargas <=
- Re: RES: [shell-script] Quebrar strings, Gilberto Martins, 2004/06/18
- Re: RES: [shell-script] Quebrar strings, Fernando Lemes da Silva, 2004/06/22
- Re: RES: [shell-script] Quebrar strings, Gilberto Martins, 2004/06/22
- Re: RES: [shell-script] Quebrar strings, Gilberto Martins, 2004/06/22
- Re: RES: [shell-script] Quebrar strings, Fernando Lemes da Silva, 2004/06/23
- Re: RES: [shell-script] Quebrar strings, Aurelio Marinho Jargas, 2004/06/22
- Re: RES: [shell-script] Quebrar strings, Gilberto Martins, 2004/06/23