shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Manipulação de arquivo


From: Rodrigo Monteiro
Subject: Re: [shell-script] Manipulação de arquivo
Date: Wed, 9 Nov 2005 08:48:24 -0300

Olá Leandro,

On 11/8/05, Leandro Valiengo <address@hidden> wrote:
> Fala grupo,
>
> tenho um arquivo deste tipo:
>
> SANDRO OLIVEIRA GEIGE   26450159        S
> SARAH DA SILVA                 36112643        N
> SARAH MARIA MARTINS      38335160        N
> SEBASTIAO ARCHANJO       33634414        S
> SELMA MARIA GOMES        33634414        S
> SERGIO DE SOUZA COSTA  33634414        N
> SERGIO ELIAS FERREIRA    24511737        S
> SERGIO LUIZ ALEXANDRE    25702636        N
>
> Onde o primeiro campo é o nome do cliente, o segundo é o telefone do cliente 
> e o terceiro é um flag.
>
> Esse arquivo foi gerado no unix, uma maquina solaris. Eu quero o seguinte.
>
> 1) Quero primeiro poder contar quantos telefones distintos eu tenho neste 
> arquivo.

awk -F'\t' '{print $2}' arquivo_log.txt | uniq | wc -l

- Aqui estou supondo que o separador de campos seja o tab (-F'\t'),
sendo assim vão existir três campos: nome, telefone e flag.
- o uniq é para não pegar telefones repetidos.
- o wc -l conta quantas linhas têm.

>
> 2) Para o telefone 33634414 quero saber se tenho flag = S

awk -F'\t' '$2 == "33634414" && $3 == "S" {print $0}' log.txt
- Aqui o awk irá mostrar as linhas que o segundo campo seja "33634414"
e o terceiro campo "S". Exemplo:

root@sepsrv123:/tmp/tmp#
root@sepsrv123:/tmp/tmp# awk -F'\t' '$2 == "33634414" && $3 == "S"
{print $0}' log.txt
SEBASTIAO ARCHANJO      33634414        S
SELMA MARIA GOMES       33634414        S
root@sepsrv123:/tmp/tmp#

>
> Esse arquivo não é posicional, ele é linha a linha.
>
> Grato,
>
> Leandro Valiengo
>

[]s

--
"Free as in Freedom, not free as in free beer"
Rodrigo Monteiro
JID: address@hidden
address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]