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

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

Re: Tratamento linha a linha


From: leonardoayres
Subject: Re: Tratamento linha a linha
Date: Thu, 16 Dec 2004 12:09:56 -0000
User-agent: eGroups-EW/0.82

Gentil,

No meu shell eu tenho estes erros:

teste.sh: let: not found
teste.sh: l[0]=Customer: not found

"Customer" é uma parte do texto do arquivo. São vários erros deste 
tipo em seqüência até terminar o arquivo.

--- Em address@hidden, Gentil de Bortoli Júnior 
<listas@b...> escreveu
> Leonardo, teste esse script:
> 
> #!/bin/bash
> clear
> echo "Arquivo Original"
> echo "-----------------------------------------"
> cat Teste.txt
> echo "-----------------------------------------"
> echo
> 
> for linha in `cat Teste.txt`; do
>      let i++
>      l[${i}]=${linha}
> done
> 
> echo "Arquivo Tratado"
> echo "-----------------------------------------"
> for linha in `seq ${i}`; do
>      if [ "${l[${linha}]}" == "A" ]; then
>          echo "${l[$((${linha}+1))]}|7"
>      elif [ "${l[${linha}]}" == "B" ]; then
>          echo "${l[$((${linha}+1))]}|3"
>      elif [ "${l[${linha}]}" == "D" ]; then
>          echo "${l[$((${linha}+1))]}|2"
>      fi
> done
> echo "-----------------------------------------"
> 
> Eu testei com base no arquivo que vc mandou:
> 
>  > A
>  > nome1|endereco1|telefone1
>  >
>  > B
>  > nome2|endereco2|telefone2
>  >
>  > D
>  > nome3|endereco3|telefone3
>  >
>  > D
>  > nome4|endereco4|telefone4
>  >
>  > A
>  > nome5|endereco5|telefone5
>  >
>  > B
>  > nome6|endereco6|telefone6
> 
> 
> Dá para melhorá-lo. Creio que isso pode ser feito com sed tb, mas 
como 
> eu não domino sed, ainda :P, tente isso...
> 
> []s
> 
> Gentil.




reply via email to

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