Last active
March 21, 2017 17:25
-
-
Save claudijd/d8a7aa7941da432c1834d98e093ba985 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Collapses odd/even lines into single lines | |
# | |
# Example: | |
# Thing1 | |
# description for thing1 | |
# Thing2 | |
# description for thing2 | |
# | |
# Is translated to... | |
# Thing1 description for thing1 | |
# Thing2 description for thing2 | |
file_contents = File.read(ARGV[0]).split("\n") | |
line_buffer = "" | |
file_contents.each_with_index do |line,i| | |
if i % 2 == 0 | |
line_buffer = "" | |
line_buffer += line.chomp | |
next | |
else | |
line_buffer += " " + line.chomp | |
puts line_buffer | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
$ ruby ~/Desktop/line_sorter.rb ~/Desktop/test.txt
CSC1233 something something
CSC1234 something something else