This is the bocoup web log with posts from Al, Boaz, Rick, Sam, Nate, Nick & Pete. You should also make sure to checkout code.bocoup.com, where we keep the finished versions of ideas we kick around here.


Jul 15, 2009

Ubuntu Read line from file

Cool command of the week… “head”

Head reads part of a file, this an be done by lines, or by bytes. It’s faster by bytes, for obvious disk IO reasons, but line numbers will probably be more useful in most cases anyway.

Here’s a sample….

head -n 99000000 mozdl.tsv | tail -n 1;

-n 99000000 tells the machine to read from the 99 millionth line of mozdl.tsv

| tail -n 1 tells the machine how many lines to output from where it began… one

I find myself using this command a lot, especially with bytes to jump around a file to sample data without having to expend cycles processing \n characters.



Comments:




Please send your questions to this address or call Bocoup at 617-379-2752
This web page is proudly maintained by Bocoup and hosted by (mt) Media Temple
All code on this website is Open Source