Skip to content

Instantly share code, notes, and snippets.

@adparadise
Created December 8, 2011 04:56
Show Gist options
  • Save adparadise/1446160 to your computer and use it in GitHub Desktop.
Save adparadise/1446160 to your computer and use it in GitHub Desktop.
Trivial example of traversing a large file via command line.
#!/usr/bin/env ruby
filename = ARGV[0]
usage = "USAGE: largefile.rb <filename>"
unless filename
STDERR.write(usage + "\n")
exit(1)
end
fd = IO.sysopen(filename, "r")
file = IO.new(fd, "r")
while (!file.eof?) do
line = file.gets
STDOUT.write(line)
end
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment