Skip to content

Instantly share code, notes, and snippets.

@jasper-lyons
Created August 19, 2016 12:03
Show Gist options
  • Save jasper-lyons/777a1f29b4742cfcd0cdf25114bb2734 to your computer and use it in GitHub Desktop.
Save jasper-lyons/777a1f29b4742cfcd0cdf25114bb2734 to your computer and use it in GitHub Desktop.
Zipping lists in a text file
Given:
(1, 2, 3, 4, 5), (a, b, c, d ,e ,f)
run:
V:!ruby -e "puts ARGF.read.scan(/\(([^()]*)\)/).map {|m| m[0].split(',') }.inject {|a,b| a.zip(b) }.map {|m| \"(\#{m.join(', ')})\"}.join(', ')"
and get:
(1, a), ( 2, b), ( 3, c), ( 4, d), ( 5, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment