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

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

Re: Contar linhas entre um determinado texto


From: mop
Subject: Re: Contar linhas entre um determinado texto
Date: Fri, 09 May 2008 14:20:35 -0300

Eis uma idéia com shell.
Considerei que o shell lá é o ksh.
Eu só tenho o ksh93.
Montei uma função "conta".

$ cat s
#!/bin/ksh
conta(){
L=${#1};x=0
while read R;do
 if [ $A ];then
  if [ $B ];then
   [ "${R:0:1}" == + ]&&B=||{
    #echo "$R"
    x=$(($x+1)) 
   }
  else 
   [ "${R:0:1}" == + ]&&B=1
  fi
 else
  [ "${R:0:$L}" == "$1" ]&&A=1
 fi
done
echo $x
}

cat file|conta "| SOURCE DIR"

#---fim do arquivo


Executando:
$ ./s                                                                
7


Como base:
$ cat file
| data/input | zzzzzzzzzzzzz.file |
+-------------------------------------------------------------+
| listing for ROBERT +
+-------------------------------+-----------------------------+
| SOURCE DIR | SOURCE FILE |
+-------------------------------+-----------------------------+
| data/input | 1147.file |
| data/input | 1478.file |
| data/input | 1483.file |
| data/input | 2847.file |
| data/input | 8284.file |
| data/input | 8157.file |
| data/input | 1118.file |
+-------------------------------+----------------------------+
| data/input | zzzzzzzzzzzzz.file |




------------------------------------------
>From: "Roberto Alves" <address@hidden>
>Date: Fri, 9 May 2008 14:05:00 -0300
>
>Mop,
>eu levei o arquivo pro Linux e testei mas não funcionou não.
>Queria ver por curiosidade.
>Achei que o comando separava o que vinha antes e depois do padrão que voce
>procurou mas não deu.
>De qq maneira eu nao posso correr o script no linux.
>Vou ter que ver o que fazer no AIX que tem limitações nos comandos e suas
>opções.




reply via email to

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