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

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

Re: [shell-script] Recuperar uma linha de arquivo


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] Recuperar uma linha de arquivo
Date: Sat, 25 Aug 2007 22:06:34 -0300

Muito pertinente esta dúvida.

Vamos olhar no sed1liners, principalmente o ultimo método:

 # print line number 52
 sed -n '52p'                 # method 1
 sed '52!d'                   # method 2
 sed '52q;d'                  # method 3, efficient on large files

Vejamos o motivo pelo qual o comando q pode agilizar o processo:

"On line selection or deletion in which you only need to output lines
from the first part of the file, a "quit" command (q) in the script
will drastically reduce processing time for large files. Thus:

   sed -n '45,50p' filename           # print line nos. 45-50 of a file
   sed -n '51q;45,50p' filename       # same, but executes much faster

A versão em AWK ficaria:

awk 'NR==52{ print ; exit }' filename

On 8/25/07, Leonardo Fedalto <address@hidden> wrote:
>
> sed -n 1234p arquivo
>
>  On 8/25/07, William José Vicente <address@hidden> wrote:
>  >
>  >   Pessoal,
>  >
>  > alguém sabe uma forma mais eficiente de recuperar uma determinada linha
>  > de um arquivo?
-- 
Tiago B Peczenyj
Linux User #405772

http://peczenyj.blogspot.com/


reply via email to

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