1

I have a rather large text corpus, of which I would like to check a few lines to see if the format is correct (and to just generally get some idea of its contents). Is there a simple one-liner that can be used to print just the first few lines of a huge text file?

Personally I'm using PowerShell, but answers are appreciated for bash and several other shells.

wen
  • 3,782
  • 9
  • 34
  • 54

4 Answers4

3

In powershell

get-content c:\filename.txt -TotalCount 3 #here just the first 3 line.
CB.
  • 58,865
  • 9
  • 159
  • 159
  • I believe that if the file is big it will take time to produce results this way [`as question says its a large text corpus`]? – Angshuman Agarwal Jun 21 '12 at 16:25
  • @AngshumanAgarwal Tested with a 100MB file not seem to be slow. Don't know with a 1GB file. – CB. Jun 21 '12 at 16:59
1

The n first lines

head -n filename

The n first bytes

dd if=filename bs=1 count=n
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
1
$ head yourfile.txt

I'm certain there's an equivalent in PowerShell. I mean, there must be, right?

Edit: Yep. Windows equivalent of the 'tail' command

Community
  • 1
  • 1
Jordan Running
  • 102,619
  • 17
  • 182
  • 182
1

You can use less. It's very efficient with large files. And, if you need to see more* you can continue paging through the file.

*"less is more"

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439