LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] grepping file contents

[ILUG] grepping file contents

Pádraig Brady P at draigBrady.com
Wed Oct 11 09:55:45 IST 2006


Brian Foster wrote:
>   | Date: Tue, 10 Oct 2006 13:36:29 +0530
>   | From: "Walter Faleiro" <curtorkar at gmail.com>
>   | 
>   | Currently I am stuck with a mailbox of 950M.  I need to yank
>   | lines from the line number 16186834 to 16204487.  [ ... ]
>   | Can I use a command that will "cut" lines from 16186834 to
>   | 16204487 and redirect the output to another file?
> 
>  sed -n -e 16186834,16204487p
> 
>   should do it;  and to be a shade faster
>   (esp. if the last line, 16204487, is not
>   "close" to the end)
> 
>  sed -n -e 16186834,16204487p -e 16204487q

Even with the quit early, sed is slower than `head | tail`
Even though there is an extra copy involved between head and tail,
sed's line processing and script processing overhead is greater:

$ grep MemTotal /proc/meminfo
MemTotal:      1027836 kB
$ yes 0123456789 | head -20000000 > lines
$ time head -16204487 < lines | tail -17653 > /dev/null
real    0m0.893s
$ time sed -n '16186834,16204487p;16204487q' < lines > /dev/null
real    0m15.140s
$ export LANG=C
$ time head -16204487 < lines | tail -17653 > /dev/null
real    0m0.893s
$ time sed -n '16186834,16204487p;16204487q' < lines > /dev/null
real    0m3.307s

Pádraig.



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell