Skip to content

Instantly share code, notes, and snippets.

@robmiller
Created November 20, 2013 12:38
Show Gist options
  • Select an option

  • Save robmiller/7562495 to your computer and use it in GitHub Desktop.

Select an option

Save robmiller/7562495 to your computer and use it in GitHub Desktop.
Ruby one-liner for transposing rows to columns
echo "foo\nbar\nbaz\nfoo\nbar\nbaz" | ruby -pe 'BEGIN{i=0}; $_.chomp! << "\t" unless (i += 1) % 3 == 0'
# Input:
#
# foo
# bar
# baz
# foo
# bar
# baz
#
# Output:
#
# foo bar baz
# foo bar baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment