Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

grep - última ocorrência

691 views
Skip to first unread message

Gerson Haus

unread,
Apr 1, 2010, 4:40:02 PM4/1/10
to
Senhores,

Preciso que o grep me retorne somente a última linha de cada arquivo que contém a string Received.

$ grep Received *   - retorna todas as ocorrências, porém só quero a última ocorrência em cada arquivo.

Grato,
Gerson.



Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 - Celebridades - Música - Esportes

Bruno Silva

unread,
Apr 1, 2010, 4:40:02 PM4/1/10
to
grep Received * | xargs tail -1

ve se funciona desse jeito.

abraços!

2010/4/1 Gerson Haus <haus_c...@yahoo.com.br>

Francisco Aparecido da Silva

unread,
Apr 1, 2010, 5:10:02 PM4/1/10
to
Acredito que se voce usar o sort -u poderá resolver este problema.

Gerson Haus wrote:
> X-Mailer: YahooMailRC/324.3 YahooMailWebService/0.8.100.260964
> Date: Thu, 1 Apr 2010 13:30:09 -0700 (PDT)
> From: Gerson Haus <haus_c...@yahoo.com.br>
> Subject: grep - última ocorrência
> To: debian-user...@lists.debian.org


>
> Senhores,
>
> Preciso que o grep me retorne somente a última linha de cada arquivo que contém a string Received.
>
> $ grep Received * - retorna todas as ocorrências, porém só quero a última ocorrência em cada arquivo.
>
> Grato,
> Gerson.
>
>

> ____________________________________________________________________________________


> Veja quais são os assuntos do momento no Yahoo! +Buscados

> http://br.maisbuscados.yahoo.com
--
Francisco Aparecido da silva(fafanet)
-------------------------------------
Blog: http://blog.silva.eti.br
Home Page http://silva.eti.br
http://www.twitter.com/fafanete
http://www.identi.ca/fafanet
GNU/Linux user:239412 GPG ID:01BC73D6
-------------------------------------
/\ Document Freedom Day - Liberate your documents
_\/` http://documentfreedom.org/ - March 31st 2010

signature.asc

Gerson Haus

unread,
Apr 1, 2010, 6:00:01 PM4/1/10
to
Não deu  :(

$ grep Received * | xargs tail -1
tail: option used in invalid context -- 1

Gerson.


De: Bruno Silva <boss....@gmail.com>
Para: Gerson Haus <haus_c...@yahoo.com.br>
Cc: debian-user...@lists.debian.org
Enviadas: Quinta-feira, 1 de Abril de 2010 17:34:19
Assunto: Re: grep - última ocorrência

Gerson Haus

unread,
Apr 1, 2010, 6:10:01 PM4/1/10
to
Não sei se usei da maneiro correta, mas ele mostrou todas as ocorrências:

$ grep Received * | sort -u
rec1.txt:Received 1
rec1.txt:Received 2
rec1.txt:Received 3
rec1.txt:Received 4
rec1.txt:Received último
rec2.txt:Received último
rec3.txt:Received 1
rec3.txt:Received 2
rec3.txt:Received 3
rec3.txt:Received 4
rec3.txt:Received último
rec4.txt:Received 1
rec4.txt:Received 2
rec4.txt:Received 3
rec4.txt:Received 4
rec4.txt:Received último
rec5.txt:Received último
rec.txt:Received 1
rec.txt:Received 2
rec.txt:Received último

A saída que preciso é:
rec1.txt:Received último
rec2.txt:Received último
rec3.txt:Received último
rec4.txt:Received último
rec5.txt:Received último

é claro que 1, 2, 3, 4 último, só coloquei como referência para saber a ordem que Received estava dentro do arquivo.

Att,
Gerson.


De: Francisco Aparecido da Silva <fran...@silva.eti.br>
Enviadas: Quinta-feira, 1 de Abril de 2010 17:35:26

Assunto: Re: grep - última ocorrência

Fabiano Pires

unread,
Apr 1, 2010, 6:30:01 PM4/1/10
to
find * -exec grep Received * {} | tail -n1 \;

--
Fabiano Pires
Linux Professional Institute Certified - Level 2
ITIL Foundations Certified
http://pragasdigitais.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/z2q11d14faa1004011523sf...@mail.gmail.com

Fabricio Cannini

unread,
Apr 1, 2010, 6:30:02 PM4/1/10
to
On Thursday 01 April 2010 17:34:19 Bruno Silva wrote:
> grep Received * | xargs tail -1

'grep Received * | xargs tail -n 1' ?


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/201004011922....@yahoo.com.br

Gunther Furtado

unread,
Apr 1, 2010, 7:10:01 PM4/1/10
to
Em Thu, 1 Apr 2010 19:22:27 -0300,
Fabricio Cannini <fcan...@yahoo.com.br> escreveu:

> grep Received * | xargs tail -n 1


aqui funcionou sem o xargs

$ history | grep aptitude | tail -n 1
507 history | grep aptitude | tail -n 1


abraço,

--

"...agora, só nos sobrou o futuro...", visto em www.manuchao.net

Gunther Furtado
Curitiba - Paran__ - Brasil
gunfu...@gmail.com


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/20100401195...@papel.gfcm.net

Gerson Haus

unread,
Apr 1, 2010, 7:50:01 PM4/1/10
to
ainda não...

$ grep Received * | xargs tail -n 1
tail: cannot open `rec1.txt:Received' for reading: No such file or directory
tail: cannot open `1' for reading: No such file or directory
tail: cannot open `rec1.txt:Received' for reading: No such file or directory
tail: cannot open `2' for reading: No such file or directory
tail: cannot open `rec1.txt:Received' for reading: No such file or directory
tail: cannot open `3' for reading: No such file or directory
tail: cannot open `rec1.txt:Received' for reading: No such file or directory
tail: cannot open `4' for reading: No such file or directory
tail: cannot open `rec1.txt:Received' for reading: No such file or directory
tail: cannot open `último' for reading: No such file or directory
tail: cannot open `rec2.txt:Received' for reading: No such file or directory
tail: cannot open `último' for reading: No such file or directory
tail: cannot open `rec3.txt:Received' for reading: No such file or directory
...
...

Gerson Haus

unread,
Apr 1, 2010, 7:50:01 PM4/1/10
to
:(
$ find * -exec grep Received * {} | tail -n1 \;
tail: cannot open `;' for reading: No such file or directory
find: missing argument to `-exec'

Gerson Haus

unread,
Apr 1, 2010, 8:00:02 PM4/1/10
to
Sem o xargs deu sinal de melhoras!

$ grep Received * | tail -n 1
rec.txt:Received último

Mas só aparece o último "Received" do último arquivo.

Parece que só falta aquele "for 'todos os arquivos' repeat ... alguém está com o "shell script" menos enferrujado do que eu?

Grato,
Gerson.

Gerson Haus

unread,
Apr 1, 2010, 8:00:02 PM4/1/10
to
Sem o xargs deu sinal de melhoras!

$ grep Received * | tail -n 1
rec.txt:Received último

Mas só aparece o último "Received" do último arquivo.

Parece que só falta aquele "for 'todos os arquivos' repeat ... alguém está com o "shell script" menos enferrujado do que eu?

Grato,
Gerson.

Henry

unread,
Apr 1, 2010, 8:20:02 PM4/1/10
to
Em Quinta-feira 01 Abril 2010, ᅵs 20:56:45, Gerson Haus escreveu:
> Sem o xargs deu sinal de melhoras!
>
> $ grep Received * | tail -n 1
> rec.txt:Received ᅵltimo
>
> Mas sᅵ aparece o ᅵltimo "Received" do ᅵltimo arquivo.
>
> Parece que sᅵ falta aquele "for 'todos os arquivos' repeat ... alguᅵm estᅵ

> com o "shell script" menos enferrujado do que eu?
>
> Grato,
> Gerson.
>


for a in * ; do grep -H ^Received "$a" | tail -n1 ; done

se quiser tirar o arquivo:Received do resultado, tira o -H.

[ ]s, Henry


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/201004012115.1...@yahoo.com.br

Gerson Haus

unread,
Apr 1, 2010, 8:40:02 PM4/1/10
to
Perfeito!

$ for a in * ; do grep -H ^Received "$a" | tail -n1 ; done

rec1.txt:Received último
rec2.txt:Received último
rec3.txt:Received último
rec4.txt:Received último
rec5.txt:Received último
rec.txt:Received último

Muito obrigado a todos que colaboraram !!! A gente aprende um pouco a cada tentativa.

Att,
Gerson.


Em Quinta-feira 01 Abril 2010, às 20:56:45, Gerson Haus escreveu:
> Sem o xargs deu sinal de melhoras!
>
> $ grep Received * | tail -n 1
> rec.txt:Received último
>
> Mas só aparece o último "Received" do último arquivo.
>
> Parece que só falta aquele "for 'todos os arquivos' repeat ... alguém está

>  com o "shell script" menos enferrujado do que eu?
>
> Grato,
> Gerson.
>


for a in * ; do grep -H ^Received "$a" | tail -n1 ; done

se quiser tirar o arquivo:Received do resultado, tira o -H.

[ ]s, Henry


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/201004012115.1...@yahoo.com.br

Flamarion Jorge

unread,
Apr 2, 2010, 12:10:02 AM4/2/10
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gerson Haus escreveu:

grep Received * | sort -u | grep último$

- --
Flamarion Jorge
OpenPGP Key: 6CA750E1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAku1bbYACgkQ0SDRnmynUOHhoACgzDK4k1mwm/LWDZNVbwFEmTG7
ADwAn0daFI418zHZ+2q/vJclaFreKyqP
=olCo
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/4BB56DB6...@yahoo.com.br

Rogério Nunes

unread,
Apr 3, 2010, 1:20:02 PM4/3/10
to
Usa o AWK:

exemplo:

cat rec1.txt |grep -i 'Received' |awk '{print $2}' 

O $2 significa mostrar a segunda coluna, que no seu caso seria o "último".
--
    .~.
    / v \  
   /(   )\  GNU/Debian/Linux
   ^   ^

Fabricio Cannini

unread,
Apr 6, 2010, 2:10:02 PM4/6/10
to
On Saturday 03 April 2010 14:12:04 Rogério Nunes wrote:
> Usa o AWK:
>
> exemplo:
>
> cat rec1.txt |grep -i 'Received' |awk '{print $2}'
>
> O $2 significa mostrar a segunda coluna, que no seu caso seria o "último".

No awk, pra mostrar a última coluna se usa '$NF" . ;)

fabricio@maquina:~ # echo "bla blo" | awk '{print $NF}'
blo

[ ]'s


--
To UNSUBSCRIBE, email to debian-user-por...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/201004061450....@gmail.com

0 new messages