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,712
  • 9
  • 33
  • 54

4 Answers4

3

In powershell

get-content c:\filename.txt -TotalCount 3 #here just the first 3 line.
CB.
  • 56,179
  • 8
  • 151
  • 155
  • 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
  • 17,834
  • 1
  • 28
  • 34
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
  • 97,653
  • 15
  • 175
  • 173
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
  • 324,833
  • 88
  • 366
  • 429