Skip to content

Instantly share code, notes, and snippets.

@stevenyxu
Created May 19, 2012 19:15
Show Gist options
  • Save stevenyxu/2732049 to your computer and use it in GitHub Desktop.
Save stevenyxu/2732049 to your computer and use it in GitHub Desktop.
Print out unique lines in a file
previous = nil
output_buffer = File.open(ARGV[1], 'w')
File.open(ARGV[0], 'r') do |f|
prevline = nil
curline = f.gets
nextline = f.gets
while !curline.nil?
if curline != prevline && curline != nextline
output_buffer.write(curline)
end
prevline = curline
curline = nextline
nextline = f.gets
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment