Skip to content

Instantly share code, notes, and snippets.

@claudijd
Last active March 21, 2017 17:25
Show Gist options
  • Save claudijd/d8a7aa7941da432c1834d98e093ba985 to your computer and use it in GitHub Desktop.
Save claudijd/d8a7aa7941da432c1834d98e093ba985 to your computer and use it in GitHub Desktop.
# 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
@claudijd
Copy link
Author

Example usage:

$ ruby ~/Desktop/line_sorter.rb ~/Desktop/test.txt
CSC1233 something something
CSC1234 something something else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment