Created
May 19, 2012 19:15
-
-
Save stevenyxu/2732049 to your computer and use it in GitHub Desktop.
Print out unique lines in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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