PDA

View Full Version : how to get first n lines of a file



monkeyking
March 9th, 2007, 04:04 AM
i have some huge text files.
But while I test and develop, I want some small files.

So I want a way to "cat" the first n-lines to another file.
There must be some nice linux command tools for this.

Thanks in advance

23meg
March 9th, 2007, 04:09 AM
Check out head.

monkeyking
March 9th, 2007, 04:14 AM
YES!

thanks,
this is excatly what I needed :)

23meg
March 9th, 2007, 04:27 AM
You're welcome. For future reference, the apropos command is helpful when you know what you want to do, are sure some command does it, but aren't sure which one. Try this:


apropos first lines

And don't forget the forum search.

LotsOfPhil
March 9th, 2007, 04:27 PM
You could also do

sed -n 1,Np file.txt > newfile

That will put the first N lines in newfile.

LotsOfPhil
March 9th, 2007, 04:28 PM
head is a lot faster than sed, so... I am just babbling, I guess.